1、检查MySQL及相关RPM包,是否安装,如果有安装,则移除(rpm –e 名称)
# rpm -qa | grep -i mysql
mysql-libs-5.1.66-2.el6_3.x86_64
# yum -y remove mysql-libs*
2、下载对应的RPM包:
# ll
-rw-r--r-- 1 root root 18477656 Jun 22 17:13 MySQL-client-5.6.20-1.el6.x86_64.rpm
-rw-r--r-- 1 root root 3397944 Jun 22 16:53 MySQL-devel-5.6.20-1.el6.x86_64.rpm
-rw-r--r-- 1 root root 55064712 Jun 22 17:51 MySQL-server-5.6.20-1.el6.x86_64.rpm
-rw-r--r-- 1 root root 1943040 Jul 4 15:23 MySQL-shared-5.6.20-1.el6.x86_64.rpm
-rw-r--r-- 1 root root 3969732 Jul 4 15:33 MySQL-shared-compat-5.6.20-1.el6.x86_64.rpm
3、安装MySQL
# rpm -ivh MySQL-server-5.6.15-1.el6.x86_64.rpm
# rpm -ivh MySQL-devel-5.6.15-1.el6.x86_64.rpm
# rpm -ivh MySQL-client-5.6.15-1.el6.x86_64.rpm
# rpm -ivh MySQL-shared-5.6.20-1.el6.x86_64.rpm
#rpm -ivh MySQL-shared-compat-5.6.20-1.el6.x86_64.rpm
修改配置文件位置 ,配置my.cnf文件
# cp /usr/share/mysql/my-default.cnf /etc/my.cnf
4、初始化MySQL及设置密码
注意:不要创建data目录 ,初始化时会自动生成
#/usr/bin/mysql_install_db --user=mysql --datadir=/data/mysql/data
修改目前权限为mysql权限
#chown -R mysql:mysql mysql
注意:启动mysql服务前,my.cnf文件打开skip-grant-tables 。
启动MySQL服务
# service mysql start
# mysql -uroot –p
注意:执行flush privileges;后才可以创建新密码
mysql>grant all on *.* to 'root'@'localhost' IDENTIFIED BY '123456';
mysql>grant all on *.* to 'root'@'127.0.0.1' IDENTIFIED BY '123456';
删除空密码用户
mysql>delete from mysql.user where user='' or password='';
5、查看权限
mysql> use mysql;
mysql> select host,user,password from user;