open stack---MySQL无法登录

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
  • 登录

使用修改后的密码登录即可。

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,下面是部署OpenStack数据库服务器的ansible playbook,可以根据实际情况进行修改: ```yaml --- - hosts: db_servers become: true vars: # 数据库管理员用户名和密码 db_user: openstack db_pass: openstack # 数据库名称 keystone_db_name: keystone glance_db_name: glance nova_db_name: nova neutron_db_name: neutron cinder_db_name: cinder manila_db_name: manila octavia_db_name: octavia # 数据库主机IP地址 db_host: "{{ inventory_hostname }}" tasks: - name: Install MariaDB server apt: name: mariadb-server state: present - name: Start MariaDB service service: name: mariadb state: started - name: Secure MariaDB installation mysql_user: name: root password: "{{ db_root_password }}" login_password: "" state: present register: mysql_root_user - name: Create OpenStack database mysql_db: name: "{{ item }}" login_user: root login_password: "{{ db_root_password }}" state: present target: "{{ db_host }}" loop: - "{{ keystone_db_name }}" - "{{ glance_db_name }}" - "{{ nova_db_name }}" - "{{ neutron_db_name }}" - "{{ cinder_db_name }}" - "{{ manila_db_name }}" - "{{ octavia_db_name }}" - name: Create openstack user and grant privileges mysql_user: name: "{{ db_user }}" password: "{{ db_pass }}" login_user: root login_password: "{{ db_root_password }}" priv: "{{ item }}.*:ALL" host: "{{ db_host }}" state: present loop: - "{{ keystone_db_name }}" - "{{ glance_db_name }}" - "{{ nova_db_name }}" - "{{ neutron_db_name }}" - "{{ cinder_db_name }}" - "{{ manila_db_name }}" - "{{ octavia_db_name }}" - name: Flush privileges mysql_db: name: "*.*" login_user: root login_password: "{{ db_root_password }}" state: flush_privs target: "{{ db_host }}" ``` 其中,`db_servers`是数据库服务器的主机组,`db_root_password`是数据库管理员的密码,需要在调用playbook时传入。此外,需要根据实际情况修改各个数据库的名称和用户密码等信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值