create user '用户名'@'主机名' identified by '密码';
-- user1用户只能在localhost这个IP登陆mysql服务器
create user 'user1'@'localhost' identified by '123';
-- user2用户可以在任何电脑上登陆mysql服务器
create user 'user2'@'%' identified by '123';
用户创建之后,基本没有什么权限,需要给用户授权。
grant 权限1,权限2... on 数据库名.表名 to '用户名'@'主机名'
*.*
。grant create,alter,drop,insert,update,delete,select on test.* to 'user1'@'localhost';
grant all on *.* to 'user2'@'%';
revoke 权限1,权限2,... on 数据库.表名 from '用户名'@'主机名';
revoke all on test.* from 'user1'@'localhost';
show grants for '用户名'@'主机名';
show grants for 'user1'@'localhost';
drop user '用户名'@'主机名';
drop user 'user2'@'%';
mysqladmin -uroot -p password 新密码
需要在未登录
MySQL的情况下操作。
mysqladmin -uroot -p password root
输入老密码
set password for '用户名'@'主机名' = password('新密码');
需要在登录
MySQL的情况下操作。
set password for 'user1'@'localhost' = password('666666');
命令行操作SQL乱码问题
在路径:mysql的数据存储路径下 找到my.ini文件
修改内容1:
找到[mysql]命令,大概在63行左右,在其下一行添加
default-character-set=utf8
修改内容2:
找到[mysqld]命令,大概在76行左右,在其下一行添加
character-set-server=utf8
collation-server=utf8_general_ci
修改完毕后,重启MySQL57服务
show variables like 'character_%';
show variables like 'collation_%';
net stop MYSQL57
mysql5.5版本
mysqld --skip-grant-tables
mysql5.7版本
-- 修改my.ini文件
-- 在[mysqld]下方添加
skip-grant-tables = true
-- 以管理员权限运行cmd
net start MYSQL57
mysql -uroot
无密码登陆服务器mysql5.5版本
update user set authentication_string=password("root") where user="root";
mysql5.7版本
update mysql.user set authentication=passwor('root') where user='root';
flush privileges;
exit;
mysql -uroot
mysql -uroot -proot
SQL的关键字和函数名等不区分大小写,但是对于数据值是否区分大小写,和字符集与校对规则有关。
show character set;
show collation like 'gbk%';
show collation like 'utf8%';
utf8_unicode_ci和utf8_general_ci对中、英文来说没有实质的差别。
utf8_general_ci校对速度快,但准确度稍差。
utf8_unicode_ci准确度高,但校对速度稍慢。
show variables like '%_server';
show variables like '%_database';
show create database ceshi_db;
alter database 数据库名称 default character set 字符集名称 [collate 校对规则名称]
ALTER DATABASE ceshi_db DEFAULT CHARACTER SET utf8 collate utf8_general_ci;
注意:
修改了数据库的默认字符集和校对规则后,原来已经创建的表格的字符集和校对规则并不会改变,如果需要,那么需要单独修改。
show create table users;
show table status from bookstore like '%users%';
alter table 表名称 default character set 字符集名称 [collate 校对规则名称]
alter table 表名称 convert to character set 字符集名称 [collate 校对规则名称];