Linux中Mariadb卸載
1、卸載mariadb:
yum remove mariadb
2、刪除配置文件:
rm -f /etc/my.cnf1
3、刪除數據目錄:
rm -rf /var/lib/mysql/
Linux中修改mariadb數據庫root密碼
情況一:初始化數據庫
當第一安裝好數據庫時,默認沒有密碼,可以通過以下命令進行修改,確認密碼以后,一路Y即可完成任務。
mysql_secure_installation
# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): # 直接回車就可以
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y #輸入Y表示要設置密碼
New password: # 新密碼
Re-enter new password: # 確認密碼
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y # 移除匿名用戶
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y # 拒絕root遠程登錄,n, 不管y/n,都會拒絕root遠程登錄
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y # 刪除test數掘庫,y:刪除 n: 不刪除,
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y # 重新加載權限表,y.或者里啟服務也可
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
情況二:已知密碼
兩種修改方法:
1、直接在shell命令行使用 mysqladm 命令修改。
# mysqladmin -uroot -poldpassword password newpassword
這種方法的弊端在於會明文顯示密碼。
2、登陸數據庫修改密碼。
# mysql -uroot -p
2.1 更新 mysql 庫中 user 表的字段:
MariaDB [(none)]> use mysql;
MariaDB [mysql]> UPDATE user SET password=password('newpassword') WHERE user='root';
或者
MariaDB [mysql]> ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';
MariaDB [mysql]> flush privileges;
MariaDB [mysql]> exit;
2.2 或者,使用 set 指令設置root密碼:
MariaDB [(none)]> SET password for 'root'@'localhost' = password('newpassword');
MariaDB [(none)]> exit;
情況三:忘記現有密碼
1、先停掉服務。
# systemctl stop mariadb
2、使用跳過授權的方式啟動 mariadb。
# mysqld_safe - -skip-grant-tables &
[1] 1441
[root@centos7 ~]# 170531 02:10:28 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
170531 02:10:28 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
# ps -ef | grep 1441
root 1441 966 0 02:10 pts/0 00:00:00 /bin/sh /usr/bin/mysqld_safe --skip-grant-tables
mysql 1584 1441 0 02:10 pts/0 00:00:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --skip-grant-tables --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock
3、當跳過授權啟動時,可以不需要密碼直接登陸數據庫。登陸更新密碼即可。
# mysql
MariaDB [(none)]> use mysql;
MariaDB [mysql]> UPDATE user SET password=password('newpassword') WHERE user='root';
MariaDB [mysql]> flush privileges;
MariaDB [mysql]> exit;
4、關閉跳過授權啟動的進程:
# kill -9 1441
5、正常啟動 mariadb:
# systemctl start mariadb
至此完成數據庫密碼修改!