当前位置: > CentOS服务器 > 数据库服务器 > MySQL >

Centos7安装mysql-5.7.11

时间:2016-05-02 01:13来源:blog.csdn.net 作者:AnBene 举报 点击:

第一次在Centos安装MySQL,遇到很多问题,过程中一些问题分享下,有不足的地方,请指教~~

 

一.环境
1.Centos7 全安装(一些基本的软件都安装了)
2.mysql版本5.7.11

 

二.安装mySql准备
1.依赖
# yum install -y gcc-c++ make cmake bison bison-devel ncurses-devel libaio-devel perl
# yum install -y perl-Data-Dumper

2.mysql用户以及用户组
查看是否已经创建了:
 # cat /etc/passwd | grep mysql
 # cat /etc/group | grep mysql
 
 没有创建则新建mysql用户以及用户组:
# groupadd mysql
# useradd -r -g mysql mysql

3.解压源码包
# tar -zxv -f mysql-5.7.11.tar.gz

4.确认硬盘空间,mysql大概需要2G的安装空间
# df -h

 

三.安装mysql
1.cmake安装
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
  -DWITH_MYISAM_STORAGE_ENGINE=1 \
  -DWITH_INNOBASE_STORAGE_ENGINE=1 \
  -DWITH_MEMORY_STORAGE_ENGINE=1 \
  -DWITH_READLINE=1 \
  -DENABLED_LOCAL_INFILE=1 \
  -DMYSQL_DATADIR=/usr/local/mysql/data \
  -DMYSQL_USER=mysql \
  -DMYSQL_TCP_PORT=3306 \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/share/doc/boost-1.53.0

报错:CMake Error at cmake/boost.cmake:81 (MESSAGE): You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory>
解决:检查是否安装了boost
如果安装了,在cmake添加 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=boost的安装目录(这时,先下载boost_1_59_0.tar.gz,并把boost_1_59_0.tar.gz复制到boost的安装目录比较好,centos安装下载的话,可能会报"Timeout was reached"错误)
如果没安装,
# yum search boost
# yum install -y boost.x86_64

添加了boost之后,再次运行
 # cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
  -DWITH_MYISAM_STORAGE_ENGINE=1 \
  -DWITH_INNOBASE_STORAGE_ENGINE=1 \
  -DWITH_MEMORY_STORAGE_ENGINE=1 \
  -DWITH_READLINE=1 \
  -DENABLED_LOCAL_INFILE=1 \
  -DMYSQL_DATADIR=/usr/local/mysql/data \
  -DMYSQL_USER=mysql \
  -DMYSQL_TCP_PORT=3306 \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/share/doc/boost-1.53.0

2.编辑并安装
2.1 编译(时间会比较久,大概半小时左右)
# make

2.2 安装
# make install

2.3 修改配置文件/etc/my.cnf
[mysqld]
#basedir是新添加进去的,原来没有
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
#这个目录很重要,当启动mysql报错时,错误日志将在这个文件下
log-error=/usr/local/mysql/logs/mysql.log
#配置localhost.localdomain.pid路径,以免报错Starting MySQL. ERROR! The server quit without updating PID file (/usr/local/mysql/localhost.localdomain.pid).
pid-file=/usr/local/mysql/localhost.localdomain.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

2.4 修改目录拥有者
# chown -R mysql:mysql /usr/local/mysql


2.5 添加MySQL服务
在mysql安装目录下
# cp /support-files/mysql.server /etc/init.d/mysql

四.启动mysql
1.启动mysql服务
# service mysql start

2.启动mysql
2.1 登录(在mysql安装目录的bin下)
# mysql -uroot -p

报错:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
解决:使用mysql指定的mysql.sock目录
# mysql -uroot -p -S /usr/local/mysql/mysql.sock

2.2 修改密码
mysql> update user set authentication_string=PASSWORD("vst123456") where user='root';

五.遇到过的问题
1.问题:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
描述:在mysql第一次登录遇到
解决:在 /etc/my.cnf 的 mysqld下面添加 skip-grant-tables
如下,省掉了注释:
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock

symbolic-links=0

skip-grant-tables

[mysqld_safe]
log-error=/usr/local/mysql/logs/mysql.log
pid-file=/usr/local/mysql/localhost.localdomain.pid

!includedir /etc/my.cnf.d

2.问题:(1)ERROR! MySQL server PID file could not be found!
  Starting MySQL... ERROR! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid)
(2)ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/usr/local/mysql/mysql.sock'
描述:在mysql第一次登录遇到
解决:之前在没有配置 /etc/my.cnf 的 socket 和 pid-file 之前经常遇到,因为这两个参数原先是有默认值的,并不是编译安装时的指定
路径,因为在配置了指定路径之后,再也没有遇到过
如下,省掉了注释:
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock

symbolic-links=0

skip-grant-tables

[mysqld_safe]
log-error=/usr/local/mysql/logs/mysql.log
pid-file=/usr/local/mysql/localhost.localdomain.pid

!includedir /etc/my.cnf.d

3.问题:ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
描述:在mysql第一次登录修改了密码后,第二次登录时遇到
解决:mysql> alter user 'root'@'localhost' identified by 'rootadmin';(rootadmin登录密码)

4.问题:ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords.
描述:在修改密码时,没有设置过期状态为 N
解决:
第一步:修改 /etc/my.cnf 的 mysqld下面添加 skip-grant-tables ,并重启mysql
第二步:登录mysql,并重新设置密码和过期状态
mysql> update user set authentication_string=PASSWORD("vst123456"),password_expired = 'N' where user='root';
第三步:修改 /etc/my.cnf 的 mysqld下面删除 skip-grant-tables ,并重启mysql

5.问题:host 192.168.*.* is not allowed to connect to this mysql server
描述:使用客户端连接mysql时报错
解决:
(1)端口原因,没开放3306端口
# firewall-cmd --state    //查看firewall是否启动
# firewall-cmd --zone=public --add-port=3306/tcp --permanent  //添加开放端口
# firewall-cmd --reload //重启防火墙

(2)帐号不允许从远程登陆
登录mysql
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>flush privileges;
mysql>select host, user from user;

六.结束

------分隔线----------------------------
发表评论
为了和诣的生活,我关闭了评论页面,请大家到QQ群里交流吧:348944156,也欢迎关注本站微信公众号:centoscn
栏目分类