安装

参考:https://www.runoob.com/mysql/mysql-install.html

下载:http://repo.mysql.com/

管理命令

远程连接

1
mysql -uroot -pinspur@123 -h 111.111.19.236

用户管理

1
2
3
4
5
6
7
8
9
# 允许用户远程登录(mysql 8.x)
UPDATE mysql.user SET host = '%' WHERE user = 'root';
# PS:需退出重连
ALTER USER 'root'@'%' IDENTIFIED BY 'inspur@123' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'inspur@123';

# 允许用户远程登录(mysql 5.7)
grant all privileges on *.* to 'root'@'%' identified by 'Inspur@123';
flush privileges;

查询状态

1
2
3
4
5
6
7
8
9
10
11
# 查看全局参数
SHOW GLOBAL VARIABLES LIKE 'Innodb%';

# 查询状态
SHOW STATUS;

# 查询支持的存储引擎
SHOW ENGINES;

# 查询指定存储引擎状态
SHOW ENGINE INNODB STATUS;

常见问题

问题 1:初始化后,重置root密码

1
2
3
4
5
6
7
8
# 初始化方式:mysqld --initialize

# 查看初始化密码
[root@localhost log]# cat /var/log/mysqld.log | grep 'temporary password'
2021-07-27T07:56:26.750789Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: t-:33aMYyaC+

# 更改root密码
[root@localhost log]# mysqladmin -uroot -p't-:33aMYyaC+' password Inspur@123

问题 2:MySQL服务无法启动,/var/log/mysqld.log 中有如下报错,关键内容为: Can't determine file permissions

1
2
3
4
5
6
7
8
2021-10-19T09:00:38.314740Z 0 [ERROR] InnoDB: Operating system error number 13 in a file operation.
2021-10-19T09:00:38.314766Z 0 [ERROR] InnoDB: The error means mysqld does not have the access rights to the directory.
2021-10-19T09:00:38.314772Z 0 [ERROR] InnoDB: os_file_get_status() failed on './ibdata1'. Can't determine file permissions
2021-10-19T09:00:38.314781Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2021-10-19T09:00:39.415592Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2021-10-19T09:00:39.415630Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2021-10-19T09:00:39.415636Z 0 [ERROR] Failed to initialize builtin plugins.
2021-10-19T09:00:39.415642Z 0 [ERROR] Aborting

解决:关闭selinux