代码改变世界

Linux64下mysql安装和开发

2013-05-03 01:02  撞破南墙  阅读(7546)  评论(1编辑  收藏  举报

 

 

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  设置网络访问

wps_clip_image-31648

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中。