環境背景:CentOS 7.2node
1、編輯/usr/lib/systemd/system/mariadb.service 文件,在Service段中添加 |
[Service]
Type=simple
User=mysql
Group=mysql
User=mysql
Group=mysql
ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n
# Note: we set --basedir to prevent probes that might trigger SELinux alarms,
# per bug #547485
#在Server段中的ExecStart出添加以下
ExecStart=/usr/bin/mysqld_safe --basedir=/usr --skip-grant-tables --skip-networking
2、鍵入systemctl daemon-reload使其當即生效mysql |
[root@node1 ~]# systemctl daemon-reload
3、從新啓動mariadb服務並使用mysql聯入 |
[root@node1 ~]# systemctl restart mariadb.service
[root@node1 ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.44-MariaDB MariaDB Server
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
MariaDB [(none)]> UPDATE mysql.user SET Password=PASSWORD('xiaoshui') WHERE user='root' and host='localhost';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
5、退出並關閉mariadb服務並把/usr/lib/systemd/system/mariadb.service文件中剛剛添加的那兩行移除 |
ExecStart=/usr/bin/mysqld_safe --basedir=/usr
ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID
6、啓動mariadb服務,並使用新設置的密碼鏈接 |
[root@node1 ~]# mysql -u root -h localhost -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.44-MariaDB MariaDB Server
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
謝謝瀏覽...
sql