open stack—MySQL无法登录
一、问题:
[root@openstack01 ~]# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@openstack01 ~]#
二、原因:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
密码错误/无法访问
-
MySQL服务器停止
-
密码错误
三、解决方法:
1、未启动MySQL服务
[root@openstack01 ~]# systemctl restart mysqld
##或者
[root@openstack01 ~]# systemctl restart mariadb
以上完成重启,如果还不可以,则进行修改密码
2、修改密码
- 修改/etc/my.cnf文件,在[mysqld]中添加skip-grant-tables(登录时跳过权限检查)
[root@openstack01 ~]# vi /etc/my.cnf
[root@openstack01 ~]# cat /etc/my.cnf
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]
#
# This group is read by the server
#
[mysqld]
skip-grant-tables ##添加
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
[root@openstack01 ~]#
- 重启数据库
[root@openstack01 ~]# systemctl restart mysqld
##或者
[root@openstack01 ~]# systemctl restart mariadb
- 修改密码
登录mysql,输入密码时直接回车
[root@openstack01 ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 542
Server version: 10.3.20-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
输入use mysql
MariaDB [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [mysql]>
设置密码
##设置密码为wang@8218(自己设置,注意格式)
MariaDB [mysql]> set password for `root`@`localhost`=password('wang@8218');
ERROR 1290 (HY000): The MariaDB server is running with the --skip-grant-tables option so it cannot execute this statement
MariaDB [mysql]>
##以上设置密码时遇到问题
##解决:输入flush privileges;
MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.059 sec)
##修改:方法一
MariaDB [mysql]> set password for `root`@`localhost`=password('wang@8218');
##修改:方法二
MariaDB [mysql]> update mysql.user set authentication_string ='Wangkun@123' where user="root";
Query OK, 1 row affected (0.001 sec)
Rows matched: 1 Changed: 1 Warnings: 0
##退出
MariaDB [mysql]> exit
Bye
[root@openstack01 ~]#
- 去除
my.cnf
中的skip-grant-tables
[root@openstack01 ~]# vi /etc/my.cnf
[root@openstack01 ~]# cat /etc/my.cnf
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]
#
# This group is read by the server
#
[mysqld]
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
[root@openstack01 ~]#
- 重启服务
[root@openstack01 ~]# systemctl restart mysqld
##或者
[root@openstack01 ~]# systemctl restart mariadb
- 登录
使用修改后的密码登录即可。