2011年7月22日

Linux下修改默認MySQL的root管理密碼

Linux MySQL的幾個重要目錄

1、數據庫目錄
/var/lib/mysql/
2、配置文件
/usr/share /mysql(mysql.server命令及配置文件)
3、相關命令
/usr/bin(mysqladmin mysqldump等命令)
4、啟動腳本

/etc/rc.d/init.d/(啟動腳本文件mysql的目錄)


Linux MySQL修改登錄密碼

Linux MySQL默認沒有密碼,安裝完畢增加密碼的重要性是不言而喻的。

1、命令
usr/bin/mysqladmin -u root password 'new-password'
格式:mysqladmin -u用戶名 -p舊密碼 password 新密碼

2、例子
例1:給root加個密碼123456。
鍵入以下命令 :
[root@www.linuxidc.com local]# /usr/bin/mysqladmin -u root password123456
註:因為開始時root沒有密碼,所以-p舊密碼一項就可以省略了。

3、測試是否修改成功
1)不用密碼登錄
[root@www.linuxidc.com local]# mysql
ERROR 1045: Access denied for user: 'root@localhost' (Usingpassword: NO)
顯示錯誤,說明密碼已經修改。
2)用修改後的密碼登錄
[root@www.linuxidc.com local]# mysql -u root -p
Enter password: (輸入修改後的密碼123456)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4 to server version:4.0.16-standard
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
成功! 這是通過mysqladmin命令修改口令,也可通過修改庫來更改口令。

Linux MySQL啟動與停止

1、啟動
MySQL安裝完成後啟動文件mysql在/etc/init.d目錄下,在需要啟動時運行下面命令即可。
[root@www.linuxidc.com init.d]# /etc/init.d/mysql start另外安裝程序把MySQL安裝成了service,所以在任何目錄下都可以用:# service mysql start啟動LinuxMySQL。
2、停止
/usr/bin/mysqladmin -u root -p shutdown 或者:# service mysqlstop
3、自動啟動
1)察看mysql是否在自動啟動列表中
[root@www.linuxidc.com local]# /sbin/chkconfig –list
2)把Linux MySQL添加到你系統的啟動服務組裡面去
[root@www.linuxidc.com local]# /sbin/chkconfig – add mysql
3)把Linux MySQL從啟動服務組裡面刪除。
[root@www.linuxidc.com local]# /sbin/chkconfig – del mysql

http://www.linuxidc.com/Linux/2011-07/38945.htm

沒有留言:

發佈留言