1.1 下載
下載地址: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 檢查老版本並卸載
http://blog.sina.com.cn/s/blog_48d5933f0100ts7t.html
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 安裝
[root@localhost 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!
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。
鍵入以下命令 :
[root@test1 local]# /usr/bin/mysqladmin -u root password 123456
注:因為開始時root沒有密碼,所以-p舊密碼一項就可以省略了。
3、測試是否修改成功
1)不用密碼登錄
[root@test1 local]# mysql
ERROR 1045: Access denied for user: 'root@localhost' (Using password: NO)
顯示錯誤,說明密碼已經修改。
2)用修改后的密碼登錄
[root@test1 local]# mysql -u root -p
1.5 設置網絡訪問
mysql>grant all privileges on *.* to 'root'@'%' identified by 'andrew’ ;
給來自任何IP地址的用戶user分配可對所有數據庫的所有表進行所有操作的權限限,並設定口令為'andrew'。
1.6 編譯運行mysql程序
gcc -ofile1 file1.c -lmysqlclient -lpthread -ldl -lm -I/usr/include/mysql/ -L/usr/lib64/mysql
1.7 報錯
/bin/ld: cannot find -lmysqlclient
1.7.1 解決辦法1:(測試可行)
64位Linux系統下,源碼編譯時,有時會無法鏈接libmysqlclient庫:
/usr/bin/ld: skipping incompatible /usr/lib/mysql/libmysqlclient.so when searching for -lmysqlclient
/usr/bin/ld: skipping incompatible /usr/lib/mysql/libmysqlclient.a when searching for -lmysqlclient
請將Makefile里面的
-L/usr/lib/mysql
改為
-L/usr/lib64/mysql
注明:此處我將-L/usr/lib64/mysql添加進eclipse下的object.mk中。