初始化报错:
[root@controller my.cnf.d]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we’ll need the current
password for the root user. If you’ve just installed MariaDB, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: NO)
登录失败:
[root@controller my.cnf.d]# mysql -uroot
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
可以通过重置mysql root密码解决
1、修改 /etc/mysql/my.cnf文件,找到mysqld关键字,在mysqld下面添加skip-grant-tables,保存退出
2、重启 systemctl restart mysql
3、进行无密码登录 mysql -uroot
4、修改root密码
update user set password=PASSWORD(“password”) where user=“root”;
exit
5、vi /etc/mysql/my.cnf,把刚才添加的 skip-grant-tables 删掉,保存退出
6、再次重启 systemctl restart mysql
这样就完成了mysql root密码修改。
情况一:初始化时一般密码为空,可以在初始化时设置root密码,但是某种原因可能你初始化时mysql已经有初始密码了,但是你有不知道这个密码,无法进行初始化。
情况二:就是简单的忘记了root密码。
这两种情况都可以按以上方法修改root密码