Environment background: CentOS 7.2
I. Edit the/usr/lib/systemd/system/mariadb.service file and add it in the service segment |
123456789101112 |
[service] type=simple user=mysql group=mysql user= MySQL group=mysql execstartpre= Code class= "Bash plain" >/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= Code class= "Bash plain" >/usr --skip-grant-tables --skip-networking |
Ii. type Systemctl daemon-reload to make it effective immediately |
1 |
[[email protected] ~] # systemctl daemon-reload |
Third, restart the MARIADB service and use MySQL to enter |
1234567891011 |
[[email protected] ~]
# systemctl restart mariadb.service
[[email protected] ~]
# 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)]>
|
Iv. changing the password of the root user |
123456 |
< Code class= "Bash Plain" >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) |
V. Exit and close the MARIADB service and remove the two lines just added in the/usr/lib/systemd/system/mariadb.service file |
12 |
ExecStart= /usr/bin/mysqld_safe --basedir= /usr ExecStartPost= /usr/libexec/mariadb-wait-ready $MAINPID |
Vi. start the MARIADB service and connect using the newly set password |
1234567891011 |
[[email protected] ~]
# 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)]>
|
Reference: http://dashui.blog.51cto.com/11254923/1877042
Go MARIADB the root password after forgetting the workaround