1.查看系统中是否有系统自带的mysql rpm包,如果有,则需要先删除rpm的包
rpm -qa|grep mysql
yum -y remove [软件名]
2.在MySQL官网下载安装MySQL-5.6.21所需的rpm软件包
MySQL-client-5.6.27-1.rhel5.x86_64.rpm
MySQL-devel-5.6.27-1.rhel5.x86_64.rpm
MySQL-server-5.6.27-1.rhel5.x86_64.rpm
wget http://dev.mysql.com/Downloads/MySQL-5.6/MySQL-server-5.6.27-1.rhel5.x86_64.rpm
wget http://dev.mysql.com/Downloads/MySQL-5.6/MySQL-client-5.6.27-1.rhel5.x86_64.rpm
wget http://dev.mysql.com/Downloads/MySQL-5.6/MySQL-devel-5.6.27-1.rhel5.x86_64.rpm
3.安装mysql服务器端
rpm -ivh MySQL-server-5.6.27-1.rhel5.x86_64.rpm
error: Failed dependencies:
libaio.so.1()(64bit) is needed by MySQL-server-5.6.27-1.rhel5.x86_64
libaio.so.1(LIBAIO_0.1)(64bit) is needed by MySQL-server-5.6.27-1.rhel5.x86_64
libaio.so.1(LIBAIO_0.4)(64bit) is needed by MySQL-server-5.6.27-1.rhel5.x86_64
安装MySQL-server报错,原因是没有安装libaio,系统缺少libaio.so此软件包,下边yum安装一下libaio.so软件包
yum install -y libaio
安装成功后重新安装mysql服务器端rpm -ivh MySQL-server-5.6.27-1.rhel5.x86_64.rpm
warning: MySQL-server-5.6.27-1.rhel5.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
这是由于yum安装了旧版本的GPG keys造成的,解决办法在后面加上--force --nodeps
我们再次重新安装
rpm -ivh MySQL-server-5.6.27-1.rhel5.x86_64.rpm --force --nodeps
如果出现这种情况
Updating / installing...
1:MySQL-server-5.6.27-1.rhel5 ################################# [100%]
warning: user mysql does not exist - using rootwarning: group mysql does not exist - using rootFATAL ERROR: please install the following Perl modules before executing /usr/bin/mysql_install_db:
Data::Dumper
解决办法:安装autoconf库
命令:yum -y install autoconf //此包安装时会安装Data:Dumper模块
重新安装mysql服务器端
rpm -ivh MySQL-server-5.6.27-1.rhel5.x86_64.rpm --force --nodeps
4.安装mysql客户端
rpm -ivh MySQL-client-5.6.27-1.rhel5.x86_64.rpm
5.安装mysql开发
rpm -ivh MySQL-devel-5.6.27-1.rhel5.x86_64.rpm
6.初始化mysql
/usr/bin/mysql_install_db
7.修改mysql配置文件的位置
cp /usr/share/mysql/my-default.cnf /etc/my.cnf
8.修改root密码
mysql -uroot
当出现一下错误时ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'
解决办法修改/var/lib/mysql目录的读写权限
chown -R mysql.mysql /var/lib/mysql
重新启动mysql
/etc/init.d/mysql restart
执行mysql -uroot进入mysql(如果不允许设置,可在配置文件中[mysqld]中添加skip-grant-tables,设置完密码后记得删除)
USE mysql;
UPDATE user SET PASSWORD = PASSWORD ('123456');修改密码
FLUSH PRIVILEGES;刷新数据库
EXIT;
再次登录就可以使用
mysql -uroot -p
如果安装完成后native出现1862,需要使用mysqladmin -uroot -p password重新设置密码