虛擬機裏的MariaDB忘記密碼了,鏈接不上,只能重置MariaDB的密碼,步驟參考網絡mysql
[root@localhost ~]# mysql -uroot -p Enter password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) [root@localhost ~]# mysql -uroot -p Enter password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
系統版本sql
[root@localhost ~]# cat /etc/redhat-release # 查看系統版本 CentOS Linux release 7.4.1708 (Core)
MariaDB版本數據庫
Server version: 5.5.56-MariaDB MariaDB Server
[root@localhost ~]# systemctl status mariadb # 查看MariaDB數據庫狀態 ● mariadb.service - MariaDB database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled) Active: active (running) since Thu 2018-07-12 17:42:01 CST; 4min 37s ago Process: 1043 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS) Process: 989 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS) Main PID: 1042 (mysqld_safe) CGroup: /system.slice/mariadb.service ├─1042 /bin/sh /usr/bin/mysqld_safe --basedir=/usr └─1141 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin ... Jul 12 17:41:56 localhost.localdomain systemd[1]: Starting MariaDB database server... Jul 12 17:41:57 localhost.localdomain mariadb-prepare-db-dir[989]: Database MariaDB is probably initialized in /...ne. Jul 12 17:41:57 localhost.localdomain mariadb-prepare-db-dir[989]: If this is not the case, make sure the /var/l...ir. Jul 12 17:41:58 localhost.localdomain mysqld_safe[1042]: 180712 17:41:58 mysqld_safe Logging to '/var/lib/mysql...rr'. Jul 12 17:41:58 localhost.localdomain mysqld_safe[1042]: 180712 17:41:58 mysqld_safe Starting mysqld daemon wit...ysql Jul 12 17:42:01 localhost.localdomain systemd[1]: Started MariaDB database server. Hint: Some lines were ellipsized, use -l to show in full. [root@localhost ~]# systemctl stop mariadb # 中止MariaDB數據庫 [root@localhost ~]# mysqld_safe --skip-grant-tables # 安全模式進行MariaDB,而且跳過受權表 180706 17:51:16 mysqld_safe Logging to '/var/lib/mysql/localhost.localdomain.err'. 180706 17:51:16 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
[root@localhost ~]# mysql -uroot -p # 鏈接數據庫 Enter password: # 不要輸入密碼,直接回車 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 1 Server version: 5.5.56-MariaDB MariaDB Server Copyright (c) 2000, 2017, 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]> update user set password=PASSWORD("admin@1234") where user='root'; # 重置數據庫密碼 Query OK, 5 rows affected (0.00 sec) Rows matched: 5 Changed: 5 Warnings: 0 MariaDB [mysql]> flush privileges; # 刷新權限 Query OK, 0 rows affected (0.02 sec) MariaDB [mysql]> quit Bye
[root@localhost ~]# systemctl restart mariadb # 重啓MariaDB數據庫 [root@localhost ~]# mysql -uroot -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 7 Server version: 5.5.56-MariaDB MariaDB Server Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | netperformance | | performance_schema | | test | +--------------------+ 15 rows in set (0.01 sec) 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]> show tables; +---------------------------+ | Tables_in_mysql | +---------------------------+ | columns_priv | | db | | event | | func | | general_log | | help_category | | help_keyword | | help_relation | | help_topic | | host | | ndb_binlog_index | | plugin | | proc | | procs_priv | | proxies_priv | | servers | | slow_log | | tables_priv | | time_zone | | time_zone_leap_second | | time_zone_name | | time_zone_transition | | time_zone_transition_type | | user | +---------------------------+ 24 rows in set (0.00 sec) MariaDB [mysql]> select User,Host from user; +---------+-----------------------+ | User | Host | +---------+-----------------------+ | root | % | | root | 127.0.0.1 | | root | ::1 | | | localhost | | root | localhost | | | localhost.localdomain | | root | localhost.localdomain | +---------+-----------------------+ 8 rows in set (0.03 sec) MariaDB [mysql]> exit Bye
[root@localhost ~]# ps aux | grep mysql # 查看MariaDB數據庫的進程 root 6122 0.0 0.1 113260 1592 pts/0 S+ 17:51 0:00 /bin/sh /usr/bin/mysqld_safe --skip-grant-tables mysql 6206 0.4 9.2 922568 92556 pts/0 Sl+ 17:51 0:01 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --skip-grant-tables --log-error=/var/lib/mysql/localhost.localdomain.err --pid-file=localhost.localdomain.pid root 6295 0.0 0.0 112660 976 pts/2 R+ 17:55 0:00 grep --color=auto mysql [root@localhost ~]# ss -tunlp | grep 3306 # 查看MariaDB數據庫的端口 tcp LISTEN 0 50 *:3306 *:* users:(("mysqld",pid=1141,fd=14))