mysql8.x安装
2018-11-06 20:06:51 # other

查看已安装MySQL

1
dpkg -l | grep mysql

卸载MySQL

1
sudo apt autoremove --purge mysql-server mysql-client

安装MySQL

1
sudo apt install mysql-server mysql-client

常用MySQL指令

1
2
3
4
5
6
7
8
# MySQL状态
sudo systemctl status mysql
# MySQL启动
sudo service mysql start
# MySQL停止
sudo service mysql stop
# MySQL重启
sudo service mysql restart

配置文件修改

注释MySQL绑定本地登录

1
2
3
4
5
6
7
8
# 打开配置文件
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
# 注释掉这一行
# bind-address = 127.0.0.1
# 保存配置文件
:wq
# 重启MySQL
sudo service mysql restart

跳过密码登录

1
2
3
4
5
6
7
8
# 打开配置文件
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
# 在文件中加入这行
skip-grant-tables
# 保存配置文件
:wq
# 重启MySQL
sudo service mysql restart

修改密码

1
2
3
4
# 修改密码
ALTER USER 'root'@'%' IDENTIFIED BY '123456';
# 刷新权限
flush privileges;

修改远程权限

1
2
3
4
5
6
7
8
# 查看权限
select user,host from mysql.user;
# 修改加密规则
ALTER USER 'root'@'%' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;
# 更新root密码
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
# 更新权限
flush privileges;

ERROR:1819

1
2
3
4
5
6
7
8
# ERROR 1819 - Your password does not satisfy the current policy requirements
# 查看密码策略
SHOW VARIABLES LIKE 'validate_password%';
# 调整策略和密码长度
set global validate_password.policy=0;
set global validate_password.length=1;
# 刷新权限
flush privileges;

ERROR:1449

1
2
3
4
5
6
7
8
# ERROR 1449 - The user specified as a definer mysql.infoschema@localhost does not exist
# 删除用户
DROP USER 'mysql.infoschema'@'localhost';
# 创建用户
CREATE USER 'mysql.infoschema'@'localhost' IDENTIFIED BY 'password';
GRANT SELECT ON *.* TO `mysql.infoschema`@`localhost`;
# 刷新权限
flush privileges;