CentOS 7 64位下MySQL5.7安装与配置(YUM)

来源:互联网 发布:林俊杰至少还有你知乎 编辑:程序博客网 时间:2024/06/15 06:47

安装环境:CentOS 7 64位 安装MySQL5.7

第一步,在MySQL官网中下载YUM源rpm安装包:https://dev.mysql.com/downloads/repo/yum/

其他下载地址:http://mirrors.sohu.com/mysql/MySQL-5.7/ (参考:http://jingyan.baidu.com/article/4665065825c740f549e5f830.html)


下载mysql源安装包
shell> wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
安装mysql源
shell> yum mysql57-community-release-el7-11.noarch.rpm

检查mysql源是否安装成功

shell> yum repolist enabled | grep "mysql.*-community.*"
!mysql-connectors-community/x86_64       MySQL Connectors Community           42!mysql-tools-community/x86_64          MySQL Tools Community              51!mysql57-community/x86_64             MySQL 5.7 Community Server          207
看到上面所示表示安装成功。

可以查看vim /etc/yum.repos.d/mysql-community.repo源,不需要修改。
(如果需要可以改变默认安装的mysql版本。比如要安装5.6版本,将5.7源的enabled=1改成enabled=0。然后再将5.6源的enabled=0改成enabled=1即可)


第二步,安装MySQL

shell> yum install mysql-community-server
安装过程中问题报错及处理,如果没报错可以忽略
1、依赖冲突,问题如下:
错误:软件包:akonadi-mysql-1.9.2-4.el7.x86_64 (@anaconda)
          需要:mariadb-server
          正在删除: 1:mariadb-server-5.5.52-1.el7.x86_64 (@anaconda)
             mariadb-server = 1:5.5.52-1.el7
          取代,由: mysql-community-server-5.7.19-1.el7.x86_64 (mysql57-community)
              未找到
 您可以尝试添加 --skip-broken 选项来解决该问题
** 发现 3 个已存在的 RPM 数据库问题, 'yum check' 输出如下:
ipa-client-4.4.0-12.el7.centos.x86_64 有已安装冲突 freeipa-client: ipa-client-4.4.0-12.el7.centos.x86_64
ipa-client-common-4.4.0-12.el7.centos.noarch 有已安装冲突 freeipa-client-common: ipa-client-common-4.4.0-12.el7.centos.noarch
ipa-common-4.4.0-12.el7.centos.noarch 有已安装冲突 freeipa-common: ipa-common-4.4.0-12.el7.centos.noarch


解决方式:
rpm -e ipa-client-4.4.0-12.el7.centos.x86_64
rpm -e ipa-client-common-4.4.0-12.el7.centos.noarch (这个删除时报其他依赖错误,没关系执行下一步)
yum  remove  mariadb-server
重新安装  yum -y install mysql-community-server  
问题解决。


第三步,修改mysql配置文件

vi /etc/my.cnf

#datadir=/var/lib/mysql  #如果数据文件比较大,将默认路径屏蔽,改成比较大的磁盘路径
datadir=/home/mysql/data

user=mysql

character-set-server=utf8 #配置默认编码为utf8

第四步,启动MySQL服务

systemctl stop mysqld
systemctl status mysqld
systemctl start mysqld

启动过程中问题报错及处理,如果没报错可以忽略,查看日志:
启动:systemctl start mysqld报错:Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
查看:tail -100 /var/log/mysqld.log 
第一种:
2017-08-22T06:16:54.307757Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error2017-08-22T06:16:54.908321Z 0 [ERROR] Plugin 'InnoDB' init function returned error.2017-08-22T06:16:54.908373Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
第二种:
2017-08-22T06:16:34.209915Z 0 [ERROR] InnoDB: The innodb_system data file 'ibdata1' must be writable2017-08-22T06:16:34.209933Z 0 [ERROR] InnoDB: The innodb_system data file 'ibdata1' must be writable2017-08-22T06:16:34.209941Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2017-08-22T06:16:34.810359Z 0 [ERROR] Plugin 'InnoDB' init function returned error.2017-08-22T06:16:34.810389Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
第三种:
2017-08-22T08:48:24.943269Z 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist2017-08-22T08:48:24.943366Z 0 [ERROR] Aborting
解决方式:
目录赋权(由于新修改了datadir=/home/mysql/data)
chonw -R mysql.mysql /home/mysql
\rm -R 
/home/mysql/*
mysqld --initialize-insecure --user=mysql  --datadir=/home/mysql/data
systemctl stop mysqldsystemctl start mysqld
问题解决。

第五步,如果需要开机启动,设置如下

shell> systemctl enable mysqld
shell> systemctl daemon-reload

第六步,修改root本地登录密码

mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改:

shell> grep 'temporary password' /var/log/mysqld.log
shell> mysql -uroot -p  #mysql5.7装完也可以直接敲 mysql 默认root登录,不需要密码mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!'; 

或者

mysql> set password for 'root'@'localhost'=password('MyNewPass4!'); #5.7不好用,用以下的

或者

update user set authentication_string=password('root147247') where user='root';
第七步,开放远程登录
mysql -u root -p mysql>use mysql; mysql>update user set host = '%' where user = 'root'; mysql>select host, user from user;
mysql>FLUSH PRIVILEGES
默认配置文件路径: 
配置文件:/etc/my.cnf 
日志文件:/var/log/mysqld.log 
服务启动脚本:/usr/lib/systemd/system/mysqld.service 
socket文件:/var/run/mysqld/mysqld.pid
建议增加mysql-devel包安装
yum install mysql mysql-devel mysql-server mysql-utilities

其他参考文献:

http://www.linuxidc.com/Linux/2016-09/135288.htm

http://www.cnblogs.com/cnblogsfans/archive/2009/09/21/1570942.html

http://zhujiangtao.blog.51cto.com/6387416/1296931

http://blog.csdn.net/yhl_jxy/article/details/53534194

Linux下安装启动多个Mysql:

http://www.linuxidc.com/Linux/2011-03/33426.htm

http://www.jb51.net/article/87160.htm?pc

http://www.cnblogs.com/huixuexidezhu/p/6566261.html

http://www.linuxidc.com/Linux/2012-09/70153.htm

http://blog.csdn.net/tangpengtao/article/details/6867599

http://xiangcun168.blog.51cto.com/4788340/1663165

http://www.jb51.net/article/48592.htm

原创粉丝点击