1、查看系统自带的mysql
yum list installed | grep mysql
(yum list列出所有可安装的软件包列表,包含已安装和未安装的。yum list installed则显示已安装软件包列表)
2、卸载自带的安装包
yum -y remove 软件包名
(如:yum -y remove mysql-libs.x86_64)
3、给CentOS添加rpm源,并且选择较新的源
wget mysql源地址(源地址mysql官网找)
(如:wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm;如果linux上执行wget报错:unable to resolve host address解决:cat /etc/resolv.conf 可以查看DNS客户机配置文件,#cd /etc , #vi resolv.conf ,注释原来的nameserver,下方增加nameserver 8.8.8.8 #googleDNS ,nameserver 8.8.4.4 #googleDNS)
4、安装本地mysql源
yum localinstall 下载的源
(如:yum localinstall mysql-community-release-el6-5.noarch.rpm)
5、验证mysql源是否安装成功
yum repolist all | grep mysql
(yum repolist all查看您拥有的仓库)
6、修改默认版本
vi /etc/yum.repos.d/mysql-community.repo
(将把5.6的enabled=0,把5.7的enabled=1)
7、安装mysql
yum install mysql-community-server
8、启动mysql
service mysqld start
(如报错1:--initialize specified but the data directory has files in it. Aborting
处理:首先:#cat /etc/my.cnf 中的datadir路径为‘/var/lib/mysql’,
其次:#cd /var/lib/ #mv mysql mysql.bak
最后:初始化mysql:#mysqld --initialize --user=mysql ,然后启动mysql:#service mysqld start )
(报错2: os_file_get_status() failed on './ibdata1'. Can't determine file permissions【mysql5.7启动错误】(查看日志报错:#tail -50f /var/log/mysqld.log)
解决方案:关闭SELinux
临时关闭: #setenforce 0
永久关闭:vi /etc/selinux/config,将SELINUX=enforcing改为SELINUX=disabled,设置后需要重启才能生效
)
9、查看mysql 初始密码
grep 'temporary password' /var/log/mysqld.log
10、登录mysql
mysql -u root -p
(操作:show databaes,提示需修改密码)
11、修改密码的方法:
alter user root@localhost identified by '新密码';
(新修改的密码中 必须包含 大小写字母数字及符号 )