標籤:
1.1 MySQL下載
:http://www.mysql.com/downloads/mysql/5.5.html#downloads
版本:5.1.68
平台:linux general
Generic Linux (glibc 2.3) (x86, 64-bit), RPM Package
版本:MySQL Server
(MySQL-server-5.1.68-1.glibc23.x86_64.rpm)
註:這個不是最新版,但卻是我之前使用的版本,考慮相容性,使用該版本。
1.2 檢查老版本並卸載
1、尋找以前是否裝有mysql
命令:rpm -qa|grep -i mysql
可以看到mysql的兩個包:
mysql-4.1.12-3.RHEL4.1
mysqlclient10-3.23.58-4.RHEL4.1
2、刪除mysql
刪除命令:rpm -e --nodeps 包名
( rpm -ev mysql-4.1.12-3.RHEL4.1 )
3、刪除老版本mysql的開發標頭檔和庫
命令:rm -fr /usr/lib/mysql
rm -fr /usr/include/mysql
注意:卸載後/var/lib/mysql中的資料及/etc/my.cnf不會刪除,如果確定沒用後就手工刪除
rm -f /etc/my.cnf
rm -fr /var/lib/mysql
1.3 安裝
[[email protected] soft]# rpm -ivh MySQL-server-5.1.68-1.glibc23.x86_64.rpm
Preparing... ########################################### [100%]
1:MySQL-server ########################################### [100%]
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password ‘new-password‘
/usr/bin/mysqladmin -u root -h localhost.localdomain password ‘new-password‘
Alternatively you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
Please report any problems with the /usr/bin/mysqlbug script!
Starting MySQL. SUCCESS!
[[email protected] soft]# mysql
-bash: /bin/mysql: 沒有那個檔案或目錄
1.4 登入MySQL
命令是mysql, mysql 的使用文法如下:
mysql [-u username] [-h host] [-p[password]] [dbname]
username 與 password 分別是 MySQL 的使用者名稱與密碼,mysql的初始管理帳號是root,沒有密碼,注意:這個root使用者不是Linux的系統使用者。MySQL預設使用者是root,由於初始沒有密碼,第一次進時只需鍵入mysql即可。
MySQL預設沒有密碼,安裝完畢增加密碼的重要性是不言而喻的。
1、命令
usr/bin/mysqladmin -u root password ‘new-password‘
格式:mysqladmin -u使用者名稱 -p舊密碼 password 新密碼
2、例子
例1:給root加個密碼123456。
鍵入以下命令 :
[[email protected] local]# /usr/bin/mysqladmin -u root password 123456
註:因為開始時root沒有密碼,所以-p舊密碼一項就可以省略了。
3、測試是否修改成功
1)不用密碼登入
[[email protected] local]# mysql
ERROR 1045: Access denied for user: ‘[email protected]‘ (Using password: NO)
顯示錯誤,說明密碼已經修改。
2)用修改後的密碼登入
[[email protected] local]# mysql -u root -p
1.5 最後賦予存取權限(很重要,不然用戶端串連不上)
GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘123456‘ WITH GRANT OPTION;
給來自任何IP地址的使用者user分配可對所有資料庫的所有表進行所有操作的許可權限,並設定口令為‘123456‘。
linux下卸載和安裝mysql資料庫的方法