Mysql5.7 Centos7安装

. 下载解压

[root@Node201 softwares]# tar -zxvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz -C /opt
[root@Node203 softwares]# cd /opt/
[root@Node203 opt]# mv mysql-5.7.25-linux-glibc2.12-x86_64/ mysql

2. 配置my.cnf

  5.7.18之后解压后没有自带的my.cnf  

直接修改原来的mariadb的文件,没有的话,新建一个

[mysql]
default-character-set=utf8

[mysqld]
default-storage-engine=INNODB
character_set_server=utf8
basedir=/opt/mysql
datadir=/data/mysql/data
socket=/data/mysql/mysql.sock

skip_ssl
symbolic-links=0

[mysqld_safe]
log-error=/data/mysql/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

!includedir /etc/my.cnf.d

3. 新建目录

[root@Node201 support-files]# mkdir -p /data/mysql/data
[root@Node201 support-files]# mkdir -p /data/mysql/log
[root@Node201 my.cnf.d]# mkdir -p /var/run/mysqld/
[root@Node202 bin]# touch /data/mysql/log/mysqld.log   -- 启动时自己不生成

4. 复制mysql.server到/etc/init.d/目录下(目的想实现开机自动执行效果)

[root@Node202 support-files]# cp /opt/mysql/support-files/mysql.server /etc/init.d/mysql
[root@Node201 support-files]# vim /etc/init.d/mysql

修改:
basedir=/opt/mysql
datadir=/data/mysql/data

5. 新建用户并授权

新建用户
[root@Node201 support-files]# groupadd mysql
[root@Node201 support-files]# useradd -r -g mysql mysql
[root@Node201 support-files]# passwd mysql
123456

[root@Node201 local]# chown -R mysql:mysql /opt/mysql/
[root@Node201 local]# chown -R mysql:mysql /var/run/mysqld/
[root@Node201 local]# chown -R mysql:mysql  /data/mysql

6.初始化 mysql 的数据库

[root@Node201 bin]# ./mysqld --initialize --user=mysql --basedir=/opt/mysql --datadir=/data/mysql/data
记下临时密码

 


7. 加密(不是必须的)

[root@Node201 bin]# /opt/mysql/bin/mysqld --initialize --user=mysql --basedir=/opt/mysql --datadir=/data/mysql/data

8.启动

[root@Node201 bin]# ./mysqld_safe --user=mysql &

9. 查看

[root@Node203 bin]# netstat -ntlp | grep 3306
[root@Node203 bin]# ps -ef|grep mysql

10. 登录,并设置

[root@Node201 bin]# ./mysql -uroot -p -S /data/mysql/mysql.sock

mysql> set password=password("123456");
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql>  grant all privileges on *.* to'root' @'%' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> 

11. 防火墙

firewall-cmd --zone=public --add-port=3306/tcp --permanent

firewall-cmd --reload

12. 设置开机自启动

[root@Node201 bin]# chkconfig --add mysql
[root@Node201 bin]# chkconfig mysql on
[root@Node201 bin]# chkconfig --list | grep mysql

13. 环境变量

[root@Node201 bin]# vim /etc/profile
添加:
export PATH=$JAVA_HOME/bin:/opt/mysql/bin:$PATH

source /etc/profile

  

 

posted on 2019-02-21 16:44  ajistyle  阅读(226)  评论(0编辑  收藏  举报

导航