1.mysql5.7字符编码的问题
mysql5.7和之前版本,默认字符集为latin1,直接插入中文字符的时候会出现乱码的情况。所以在安装5.7及之前的版本的mysql的时候要把字符编码修改为utf8字符集,utf8字符集指的是utf8mb3。从mysql8.0开始,数据库默认字符编码改为utf8mb4。
查看编码命令:
show variables like 'character_%'; show variables like 'collation_%';
2.用户的创建与授权
在MySQL5.7的版本:
grant all privileges on *.* to 'bertram'@'localhost' identified by '1q2w3e4r';; #grant all privileges on *.* to '用户名'@'主机' identified by '密码';
在MySQL8.0需要分开执行,否则使用以前的命令在8.0里面创建用户,会出现sql语法错误:
mysql> create user 'bertram'@'localhost' identified by '1q2w3e4r'; Query OK, 0 rows affected (0.04 sec) #create user '用户名'@'主机' identified by '密码'; mysql> grant all privileges on *.* to 'bertram'@'localhost'; Query OK, 0 rows affected (0.04 sec) #grant all privileges on . to '用户名'@'主机';
注意事项:
1)、8.0系已无query_cahe参数,注释参数
2)、授权时需要分开授权,不能用grant 建立用户
CREATE USER 'myuser'@'%' IDENTIFIED BY 'mypassword';
-- 给用户分配权限
grant all privileges on *.* to 'myuser'@'%' ;
-- 单独授予某种权限的写法;具体再详细的操作请参考其他文章
GRANT SELECT ON oilsystem.input TO 'myuser'@'%';
-- 刷新权限,使操作生效
FLUSH PRIVILEGES;
3)、第一次修改root账号密码此采用alter,
不能用此方式,8系已不支持
update user set password=password("123456") where user="root";
set password=password('dengzl123');
正确修改:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'dengzl123';