####centos7 mysql5.7源码安装之二(5.7.17-linux-glibc2.5)#######
1、准备工作(创建mysql用户及其mysql用户组 生产用户目录 及其设置该账号不能登录) ,解决依赖包
[root@localhost ~]#yum -y install gcc gcc-c++ ncurses ncurses-devel cmake bison [root@localhost ~]# groupadd -r mysql && useradd -r -g mysql -s /sbin/nologin -M mysql [root@localhost ~]# mkdir /home/soft [root@localhost ~]# cd /home/soft [root@localhost soft]# wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar
注意:如果下载了是tar包,#wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar,需要先用tar -xf mysql-5.7.17-linux-glibc2.5-x86_64.tar ,解压后包含两个文件mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz和mysql-test-5.7.17-linux-glibc2.5-x86_64.tar.gz
2、解压tar.gz 并重命名 转让所属权限给mysql账号
[root@localhost soft]# tar -vxzf https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz [root@localhost soft]# mv mysql-5.7.17-linux-glibc2.5-x86_64/ /usr/local/mysql
3、创建数据库存放数据文件夹
[root@localhost soft]# mkdir -pv /mydata/data [root@localhost soft]# chown -R mysql:mysql /mydata/data/
--------------------------------------------------------
注意:(如果解压到默认路径。如可以创建软连接进行连接 如:)
需要etc/my.cnf、/etc/init.d/mysqld中修改
basedir='/apps/mysql' datadir='/apps/mysql/data'
[root@localhost soft]#mkdir -p /usr/local/mysql/bin [root@localhost soft]#ln -s /apps/mysql/bin/mysqld /usr/local/mysql/bin/mysqld
----------------------------------------------------------
4、安装和初始化
[root@localhost soft]# cd /usr/local/ [root@localhost local]# chown -R mysql:mysql mysql/ [root@localhost local]# mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/mydata/data/ [root@localhost local]# cd /mysql [root@localhost mysql]# cp -a ./support-files/my-default.cnf /etc/my.cnf #拷贝文件my.cnf
配置文件至/etc/目录下
#编辑修改my.cnf文件,添加如下参数:
[root@localhost mysql]#vim /etc/my.cnf basedir = /usr/local/mysql datadir = /mydata/data socket = /tmp/mysql.sock [root@localhost mysql]# cp -a ./support-files/mysql.server /etc/init.d/mysqld #拷贝管理启动脚本至init.d [root@localhost mysql]# ln -s /usr/local/mysql/bin/mysql /usr/bin #创建mysql软链接至/usr/bin下 [root@localhost bin]# /etc/init.d/mysqld restart [root@localhost bin]# systemctl enable mysqld.service #设置开机启动
6.初始化密码
启动mysql5.7后会生成一个初始化密码,而在之前的版本首次登陆不需要登录。
[root@localhost mysql]# cat /root/.mysql_secret # Password set for user 'root@localhost' at 2017-02-13 11:51:23 yee_g*qdJ>q7 [root@localhost bin]# ./mysql -uroot -p'yee_g*qdJ>q7'
mysql> SET PASSWORD = PASSWORD('111111'); Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
7.添加远程访问权限
mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> update user set host = '%' where user = 'root'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0
常见问题:
1、原操作系统存在mariadb包,启动时报错如下:
2017-02-13T03:33:09.721333Z mysqld_safe Logging to '/var/log/mariadb/mariadb.log'. 2017-02-13T03:33:09.748968Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
解决方法:[root@localhost mysql]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64
2、启动mysqld时,找不到myslq.pid文件或目录
2月 13 12:24:57 node03 systemd[1]: Starting LSB: start and stop MySQL... 2月 13 12:24:58 node03 mysqld[5757]: Starting MySQL./usr/local/mysql/bin/mysqld_safe:行586: /usr/loc…或目录 2月 13 12:24:58 node03 mysqld[5757]: awk: (FILENAME=- FNR=1) warning: error writing standard output …的管道) 2月 13 12:24:58 node03 mysqld[5757]: Logging to '/usr/local/mysql/data/node03.err'. 2月 13 12:24:59 node03 mysqld[5757]: ERROR! The server quit without updating PID file (/usr/local/my...pid). 2月 13 12:24:59 node03 systemd[1]: mysqld.service: control process exited, code=exited status=1 2月 13 12:24:59 node03 systemd[1]: Failed to start LSB: start and stop MySQL. 2月 13 12:24:59 node03 systemd[1]: Unit mysqld.service entered failed state. 2月 13 12:24:59 node03 systemd[1]: mysqld.service failed.
解决方法:在my.cnf配置文件中,添加basedir和datadir文件,需要跟初始化安装时,指定的目录位置一致