Cent OS 6.4安装mysql

Cent OS6.4 RPM安装mysql

一、卸载掉原有mysql

因为目前主流Linux系统版本基本上都集成了mysql数据库在里面

如下命令来查看我们的操作系统上是否已经安装了mysql数据库

[root@xiaoluo ~]# rpm -qa | grep mysql  // 这个命令就会查看该操作系统上是否已经安装了mysql数据库

有的话,我们就通过 rpm -e 命令 或者 rpm -e --nodeps 命令来卸载掉

[root@xiaoluo ~]# rpm -e mysql  // 普通删除模式
[root@xiaoluo ~]# rpm -e 已经安装的包和库文件--nodeps mysql  // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除

全部删除

在删除完以后我们可以通过 rpm -qa | grep mysql 命令来查看mysql是否已经卸载成功!!

二、下载最新Mysql

http://dev.mysql.com/downloads/mysql/ 打开网址: Select Platform: 选择 Linux-Generic

三、安装

tar -xf MySQL-5.6.22-1.linux_glibc2.5.x86_64.rpm-bundle.tar

rpm –ivh MySQL-server-5.6.26-1.linux_glibc2.5.x86_64.rpm MySQL-client-5.6.26-1.linux_glibc2.5.x86_64.rpm MySQL-devel-5.6.26-1.linux_glibc2.5.x86_64.rpm

等待安装完成

启动mysql服务

service mysql start   
Starting MySQL.......... SUCCESS! 

如果启动失败centos请检查

/etc/selinux/config

将SELINUX=enforcing设置为

SELINUX=disabled

输入mysql

新装好的mysql在进入mysql工具时,总是有错误提示:
# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
或者
# mysql -u root -p password 'newpassword'
Enter password:
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: YES)' 方法操作很简单,如下:
# /etc/init.d/mysql stop
# mysqld_safe --user=mysql --skip-grant-tables  --skip-networking

新开一个SSH窗口
# mysql -u root mysql

提示输入密码,直接回车进入

use mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root' and host='root' or host='localhost';//把空的用户密码都修改成非空的密码就行了。
mysql> FLUSH PRIVILEGES;
mysql> quit # /etc/init.d/mysqld restart
# mysql -uroot -p

Enter password: <输入新设的密码newpassword>

 

MySql5.6操作时报错:You must SET PASSWORD before executing this statement解决

mysql>  SET PASSWORD = PASSWORD('123456');
Query OK, 0 rows affected (0.03 sec)

也就是用mysql>  SET PASSWORD = PASSWORD('123456');这句话重新设置一次密码!

设置开机自动启动MySQL

chkconfig mysql on
即可设置成功。

 

原文地址:https://www.cnblogs.com/liunanjava/p/4743036.html