centos 7下mysql5.7的配置安装

来源:互联网 发布:宁夏干部网络培训网 编辑:程序博客网 时间:2024/06/05 02:13

下载安装包地址:https://dev.mysql.com/downloads/mysql/

如图:

检查是否已安装mysql

  [root@izwz93zazliojetgsr3tymz ~]# yum list installed | grep mysql 或rpm -qa | grep mysql

移除已安装包

  yum -y remove + 需移除包名

检查mysql组和用户是否存在,如无创建

[root@izwz93zazliojetgsr3tymz ~]# cat /etc/group | grep mysql [root@izwz93zazliojetgsr3tymz ~]#  cat /etc/passwd | grep mysql

创建mysql用户组

[root@izwz93zazliojetgsr3tymz ~]# groupadd mysql

创建一个用户名为mysql的用户并加入mysql用户组

[root@izwz93zazliojetgsr3tymz ~]# useradd -g mysql mysql

制定密码为123456

[root@izwz93zazliojetgsr3tymz ~]# passwd mysqlChanging password for user mysql.New password: (注意:输入密码时是不可见的!)BAD PASSWORD: The password is a palindromeRetype new password: passwd: all authentication tokens updated successfully.

安装到/usr/local (将下载好的安装包移进此目录下,解压)

[root@izwz93zazliojetgsr3tymz local]# tar -zxvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz 

重命名

[root@izwz93zazliojetgsr3tymz local]# mv mysql-5.7.18-linux-glibc2.5-x86_64/ mysql57(如果安装包不需要可执行删除[root@izwz93zazliojetgsr3tymz local]# rm -rf mysql-5.7.18-linux-      glibc2.5-x86_64.tar.gz )

更改所属的组和用户

[root@izwz93zazliojetgsr3tymz local]# chown -R mysql mysql57/[root@izwz93zazliojetgsr3tymz local]# chgrp -R mysql mysql57/[root@izwz93zazliojetgsr3tymz local]# cd mysql57/[root@izwz93zazliojetgsr3tymz mysql57]# mkdir data[root@izwz93zazliojetgsr3tymz mysql57]# chown -R mysql:mysql data

查找是否有my.cnf文件如果没有则看下一步(有则直接看下面my.cnf的配置)

[root@izwz93zazliojetgsr3tymz /]# find / -iname '*.cnf' -print/root/node-v9.0.0/test/fixtures/openssl_fips_disabled.cnf/root/node-v9.0.0/test/fixtures/openssl_fips_enabled.cnf/root/node-v9.0.0/test/fixtures/keys/fake-cnnic-root.cnf/root/node-v9.0.0/test/fixtures/keys/agent2.cnf/root/node-v9.0.0/test/fixtures/keys/agent1.cnf/root/node-v9.0.0/test/fixtures/keys/ca3.cnf/root/node-v9.0.0/test/fixtures/keys/ca1.cnf/root/node-v9.0.0/test/fixtures/keys/agent4.cnf/root/node-v9.0.0/test/fixtures/keys/ca2.cnf

没有则复制一个到/etc下

[root@izwz93zazliojetgsr3tymz /]# cp /root/node-v9.0.0/test/fixtures/keys/ca3.cnf /etc[root@izwz93zazliojetgsr3tymz /]# cd /etc

更改文件名

[root@izwz93zazliojetgsr3tymz /]# mv ca3.cnf my.cnf

在etc下my.cnf文件内添加以下配置

[mysql]# 设置mysql客户端默认字符集default-character-set=utf8 [mysqld]skip-name-resolve# 设置3306端口port = 3306 # 设置mysql的安装目录basedir=/usr/local/mysql57# 设置mysql数据库的数据的存放目录datadir=/usr/local/mysql57/data# 允许最大连接数max_connections=200# 服务端使用的字符集默认为8比特编码的latin1字符集character-set-server=utf8# 创建新表时将使用的默认存储引擎default-storage-engine=INNODB lower_case_table_names=1max_allowed_packet=16M

安装与初始化

[root@izwz93zazliojetgsr3tymz /]# cd /usr/local/mysql57[root@izwz93zazliojetgsr3tymz mysql57]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql57/ --datadir=/usr/local/mysql57/data/2017-11-29 15:19:39 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize2017-11-29 15:19:48 [WARNING] The bootstrap log isn't empty:2017-11-29 15:19:48 [WARNING] 2017-11-29T07:19:40.928235Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead[root@izwz93zazliojetgsr3tymz mysql57]# cp ./support-files/mysql.server /etc/init.d/mysqld[root@izwz93zazliojetgsr3tymz mysql57]# chown 777 /etc/my.cnf [root@izwz93zazliojetgsr3tymz mysql57]# chmod +x /etc/init.d/mysqld[root@izwz93zazliojetgsr3tymz mysql57]# /etc/init.d/mysqld restartShutting down MySQL.. SUCCESS! Starting MySQL. SUCCESS! 

设置开机启动

[root@izwz93zazliojetgsr3tymz mysql57]# chkconfig --level 35 mysqld on[root@izwz93zazliojetgsr3tymz mysql57]# chkconfig --list mysqld[root@izwz93zazliojetgsr3tymz mysql57]# chmod +x /etc/rc.d/init.d/mysqld[root@izwz93zazliojetgsr3tymz mysql57]# chkconfig --add mysqld[root@izwz93zazliojetgsr3tymz mysql57]# chkconfig --list mysqld[root@izwz93zazliojetgsr3tymz mysql57]# service mysqld status SUCCESS! MySQL running (20157)

修改/etc/profile文件

[root@izwz93zazliojetgsr3tymz mysql57]# vi /etc/profile在profile中增加此句:export PATH=$PATH:/usr/local/mysql57/bin让其生效:[root@izwz93zazliojetgsr3tymz mysql57]# source /etc/profile(此过程出现不识别指令错误退出重新进入即可!)

获得初始密码

[root@izwz93zazliojetgsr3tymz mysql57]# cat /root/.mysql_secret# Password set for user 'root@localhost' at 2017-11-29 15:19:39 Pi%hFtk0*rhI

修改密码

[root@izwz93zaz1iojetgsr3tymz /]# mysql -uroot -pEnter password: Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 4Server version: 5.7.20Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> set PASSWORD = PASSWORD('123456');Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> flush privileges;Query OK, 0 rows affected (0.01 sec)

添加远程访问权限

mysql> use mysqlReading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql> update user set host='%' where user='root';Query OK, 1 row affected (0.00 sec)Rows matched: 1  Changed: 1  Warnings: 0mysql> select host,user from user;+-----------+-----------+| host      | user      |+-----------+-----------+| %         | root      || localhost | mysql.sys |+-----------+-----------+2 rows in set (0.00 sec)# create user 'xxx'@'%' identified by '123';  这里 @‘%’ 表示在任何主机都可以登录

mysql> quit;退出重启

[root@hdp265dnsnfs bin]# /etc/init.d/mysqld restart Shutting down MySQL.. SUCCESS! Starting MySQL. SUCCESS! 

查看字符集

mysql> show variables like 'character%';

如图:

到此完结!

注意:如果是安装在阿里云服务器上,那么需要添加安全组然后进行远程连接

这里写图片描述

END!!!

原创粉丝点击