MySQL8.0启动和关闭流程
启动方式
1、 mysqld_safe &(推荐):这个脚本会监控mysqld的状态,日志会记录到文件里
2、 mysqld & 日志打印到屏幕上
3、 mysql.server
调用的执行过程:systemd ——>/etc/init.d/mysqld——–>mysql.server——>mysqld_safe &—–>mysqld &
关闭方式
mysql> shutdown;
systemctl stop mysqld
service mysqld stop
service mysqld start
mysqladmin -uroot -p123456 shutdown
忘记管理员密码
1、关闭数据库
[root@localhost ~]# /etc/init.d/mysqld stop
Shutting down MySQL… SUCCESS!
2、启动安全模式
复制代码
[root@localhost ~]# mysqld_safe –skip-grant-tables –skip-networking &
[1] 1475
[root@localhost ~]# 2020-01-18T14:07:12.861565Z mysqld_safe Logging to ‘/data/mysql/data_3306/localhost.err’.
2020-01-18T14:07:12.898677Z mysqld_safe Starting mysqld daemon with databases from /data/mysql/data_3306
复制代码
3、登录数据库,修改密码,报错:没有加载授权表
[root@localhost ~]# mysql -uroot -p123
mysql> alter user root@’localhost’ identified by ‘123456’;
ERROR 1290 (HY000): The MySQL server is running with the –skip-grant-tables option so it cannot execute this statement
4、手工加载授权表
复制代码
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> alter user root@’localhost’ identified by ‘123456’;
Query OK, 0 rows affected (0.00 sec)
复制代码
5、重启数据库
[root@localhost ~]# /etc/init.d/mysqld restart
Shutting down MySQL…2020-01-18T15:09:46.575313Z mysqld_safe mysqld from pid file /data/mysql/data_3306/localhost.pid ended
SUCCESS!
3、 测试密码
[root@localhost ~]# mysql -uroot -p123456
mysql>
Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’
1、先通过:service mysqld status 查看mysql是否启动
(没装mysql service 也可通过 /etc/rc.d/init.d/mysqld status查看)
若没启动,则启动mysql:service mysqld start
2、方法: 修改/etc/my.conf:
[mysqld]
datadir=/usr/local/mysql/data
socket=/var/lib/mysql/mysql.sock
[mysql.server]
user=mysql
basedir=/usr/local/mysql
[client]
socket=/var/lib/mysql/mysql.sock
If there is not currently a section called [client], add one at the bottom of the file and copy the socket= line under the [mysqld] section such as:
(注意:红色标记部分文件路径必须相同)
发现依旧如此,运行/etc/init.d/mysql start报错:Starting MySQLCouldn’t find MySQL manager or server
是mysqld服务没启,运行/usr/local/mysql/bin/mysqld_safe &