刚刚安装完mariadb的时候直接
update user set paddword='********'
然后用密码就登陆不上了
- 因为登录的时候mariadb会把你的输入加密后再和数据库对比
- 所以如果你直接明文写进数据库用密码当然登录不上
解决办法
1,修改配置文件 /etc/my.cnf
[root@centos7 ~]# vim /etc/my.cnf
添加一行内容skip-grant-tables
- 多说一句,一定要加对位置
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
skip-grant-tables ##加在此处不会报错
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
skip-grant-tables ##此处就会报错
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
~
- 加错位置报错如下,倒数第四行
[root@centos7 ~]# systemctl status mariadb
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
Active: active (running) since Sat 2018-02-10 20:40:12 CST; 1min 40s ago
Process: 13515 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
Process: 13483 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
Main PID: 13514 (mysqld_safe)
CGroup: /system.slice/mariadb.service
├─13514 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
└─13690 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/...
Feb 10 20:40:10 centos7.4 systemd[1]: Starting MariaDB database server...
Feb 10 20:40:10 centos7.4 mariadb-prepare-db-dir[13483]: Database MariaDB is probably initialized in /var/lib/mysql already, nothing is done.
Feb 10 20:40:10 centos7.4 mysqld_safe[13514]: 180210 20:40:10 mysqld_safe unknown option '--skip-grant-tables'
Feb 10 20:40:10 centos7.4 mysqld_safe[13514]: 180210 20:40:10 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
Feb 10 20:40:10 centos7.4 mysqld_safe[13514]: 180210 20:40:10 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Feb 10 20:40:12 centos7.4 systemd[1]: Started MariaDB database server.
2,重启服务
[root@centos7 ~]# systemctl restart mariadb
3,登录mysql
[root@centos7 ~]# mysql -u root -p
4,先看一下上次的设置的密码
MariaDB [mysql]> select user,password from user;
+------+----------+
| user | password |
+------+----------+
| root | wangwang |
| root | wangwang |
| root | wangwang |
| root | wangwang |
| | wangwang |
| | wangwang |
+------+----------+
6 rows in set (0.00 sec)
5,修改密码
MariaDB [mysql]> update user set password=password('password_here') where user='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0
MariaDB [mysql]>
6,退出数据库重新登录并查看下我们新设置的密码
[root@centos7 ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
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)]>
MariaDB [(none)]>
MariaDB [(none)]>
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 user,password from user;
+------+-------------------------------------------+
| user | password |
+------+-------------------------------------------+
| root | *D7CF602BDFB5A0765611381BBD9A992A0965500A |
| root | *D7CF602BDFB5A0765611381BBD9A992A0965500A |
| root | *D7CF602BDFB5A0765611381BBD9A992A0965500A |
| root | *D7CF602BDFB5A0765611381BBD9A992A0965500A |
+------+-------------------------------------------+
6 rows in set (0.00 sec)
MariaDB [mysql]>