centos系统上mysql的安装方式有三种:
一:源码编译安装
二:二进制包安装
三:rpm包安装
说明:源码编译安装消耗太多时间,可定制化安装选项,二进制包安装比编译安装省时间,需要初始化数据库(详细安装这里不做说明),rpm包安装是最简单的安装方式,这里仅记录rpm包安装方式。
mysql的官方提供的yum源地址:http://repo.mysql.com/yum/ ,可自行查找需要的安装版本
提供一个yum源:http://mirrors.sohu.com/mysql/
安装mysql5.7可以使用下面的repo配置,默认安装mysql5.7的最新版
[mysql57-community] name=MySQL 5.7 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/ enabled=1 gpgcheck=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
shell> sudo yum install mysql-community-server
shell> sudo service mysqld start
shell> sudo service mysqld status
注意:mysql5.7启动后默认会为root@localhost创建密码,所以mysql5.1前的安装完成后本机空密码登录的方式不再适用,所以当使用mysql客户端本机登录时会提示出错,解决办法:
方法1:A superuser account ‘root‘@‘localhost‘
is created. A password for the superuser is set and stored in the error log file. To reveal it, use the following command:
官方提示此时可以查看error日志,看到临时密码,使用临时密码登陆后需修改密码
shell> sudo grep ‘temporary password‘ /var/log/mysqld.log
shell> mysql -uroot -p
mysql> ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘MyNewPass4!‘;
说明:此版本的validate_password插件会默认安装,对密码强度要求比较强,密码必须包含大写字母、小写字母、数字,且长度至少8个字符。
方法2:使用跳过密码检测登录数据库后修改密码,然后重启数据库。
mysql5.7使用rpm包默认安装完后没有生成/etc/my.cnf,但是mysql-community-server安装完成后会生成默认的配置文件default.cnf,需要将此配置文件复制为/etc/my.cnf,然后修改/etc/my.cnf
第一步:
在/etc/my.cnf中添加参数:
skip-grant-table=1
第二步:
启动mysql
shell>/etc/init.d/mysqld start
第三步:
使用mysql客户端连接至mysql服务,执行flush privileges(如果不执行这一步可能会出现无法打开user表的情况),
mysql>user mysql;
mysql>select user,host,password from user;
mysql>grant all on *.* to root@localhost identified by "password";
mysql>flush privileges;
mysql>exit
第三步:
将/etc/my.cnf中添加的skip-gtant-table=1注释掉或者删除,重启mysql服务
shell>/etc/init.d/mysqld stop
shell>/etc/init.d/mysqld start
shell>mysql -uroot -p ‘YourPassword‘
原文:http://qikexing.blog.51cto.com/7948843/1905087