mysql运维教学(运维经第22章)

每次在linux上安装完mysql/mariadb之后都会遇到登录的问题,这时需要修改密码才能登录这时候问题来了,都登录不上了怎么修改密码?,下面我们就来说一说关于mysql运维教学?我们一起去了解并探讨一下这个问题吧!

mysql运维教学(运维经第22章)

mysql运维教学

修改MySQL初始密码

每次在linux上安装完mysql/mariadb之后都会遇到登录的问题,这时需要修改密码才能登录。这时候问题来了,都登录不上了怎么修改密码?

今天说说在登录不了的情况下怎么修改mysql密码。

1.跳过权限验证修改/etc/mysql/mariadb.conf.d/50-server.cnf 文件,添加跳过权限验证的配置项。

# 使用管理员权限打开 $ sudo vi 50-server.cnf

添加配置项

# this is read by the standalone daemon and embedded servers [server] # this is only for the mysqld standalone daemon [mysqld] # # * Basic Settings # user = mysql pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock port = 3306 basedir = /usr datadir = /var/lib/mysql tmpdir = /tmp lc-messages-dir = /usr/share/mysql skip-external-locking skip-grant-tables #跳过权限验证

2.登录并修改密码

$ mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 10.1.37-MariaDB-0 deb9u1 Debian 9.6 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 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]> select host,user,password from user; ----------- ------ ---------- | host | user | password | ----------- ------ ---------- | localhost | root | | ----------- ------ ---------- 1 row in set (0.00 sec) MariaDB [mysql]> UPDATE user SET Password = password ('123456') WHERE User = 'root' ; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 MariaDB [mysql]> select host,user,password from user; ----------- ------ ------------------------------------------- | host | user | password | ----------- ------ ------------------------------------------- | localhost | root | *6A6D8D007B938C064A178AB17AED64EFDC088C6D | ----------- ------ ------------------------------------------- 1 row in set (0.00 sec) MariaDB [mysql]> MariaDB [mysql]> flush privileges; Query OK, 0 rows affected (0.00 sec) MariaDB [mysql]> exit

3.重新使用新密码登录重要:先要重新启动mysql/mariadb

(base) frank@deepin:/etc/mysql/mariadb.conf.d$ mysql -uroot -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 10.1.37-MariaDB-0 deb9u1 Debian 9.6 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)]>

4.最后不要忘了把刚才跳过权限验证的配置去掉然后重启mysql/mariadb。

,

免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com

    分享
    投诉
    首页