日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Mariadb修改root密码

發布時間:2025/5/22 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Mariadb修改root密码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

默認情況下,新安裝的 mariadb 的密碼為空,在shell終端直接輸入 mysql 就能登陸數據庫。

如果是剛安裝第一次使用,請使用 mysql_secure_installation 命令初始化。

# mysql_secure_installationNOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDBSERVERS 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 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... 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- 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... 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!

這里針對的是知道 root 密碼,而需要修改的情況。

兩種修改方法:

1、直接在shell命令行使用 mysqladm 命令修改。

# mysqladmin -uroot -poldpassword password newpassword這種方法的弊端在于會明文顯示密碼。

2、登陸數據庫修改密碼。

# mysql -uroot -p2.1 更新 mysql 庫中 user 表的字段: MariaDB [(none)]> use mysql; MariaDB [mysql]> UPDATE user SET password=password('newpassword') WHERE user='root'; MariaDB [mysql]> flush privileges; MariaDB [mysql]> exit;2.2 或者,使用 set 指令設置root密碼: MariaDB [(none)]> SET password for 'root'@'localhost'=password('newpassword'); MariaDB [(none)]> exit;

如果是忘記了 root 密碼,則需要以跳過授權的方式啟動 mariadb 來修改密碼。

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

轉載于:https://www.cnblogs.com/keithtt/p/6922378.html

總結

以上是生活随笔為你收集整理的Mariadb修改root密码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。