centos7安装Mysql5.7

准备

  • centos 7
  • mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz

安装

1.将安装包上传至/usr/local/

tar -xzvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz

解压后使用mv命令重命名,简化为mysql

mv mysql-5.7.26-linux-glibc2.12-x86_64 mysql

2.创建mysql用户和用户组

groupadd mysql
useradd -r -g mysql mysql
chown -R mysql mysql/
chgrp -R mysql mysql/

更改mysql目录的归属用户/组

chown -R mysql mysql/
chgrp -R mysql mysql/

3.修改配置文件/etc/my.cnf (复制以下内容覆盖即可)

[client]
default-character-set = utf8

[mysqld]

port=3306
max_connections=1000
wait_timeout = 600
interactive_timeout = 600
max_allowed_packet = 20M

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
lower_case_table_names=1
bind-address=0.0.0.0
character-set-server = utf8

datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/tmp/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

symbolic-links=0

[mysqld_safe]
#log-error=/var/log/mariadb/mariadb.log
#pid-file=/var/run/mariadb/mariadb.pid

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

4.按照配置文件创建对应的文件和目录

  • /usr/local/mysql/data
  • /tmp/mysql.sock
  • /var/log/mysqld.log
  • /var/run/mysqld/mysqld.pid

创建完成后修改日志文件的归属

cd /var/log/
chown mysql:mysql mysqld.log
cd /var/run/mysqld
chown mysql:mysql mysqld.pid

5.初始化Mysql

/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --lc_messages_dir=/usr/local/mysql/share --lc_messages=en_US`

6.初始化成功后,查看mysql初始密码

cat /var/log/mysqld.log 

7.设置开机启动

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld

8.启动

service mysqld start

9.配置环境变量,添加export PATH=$PATH:/usr/local/mysql/bin

vim /etc/profile
#添加export PATH=$PATH:/usr/local/mysql/bin

source /etc/profile

10.进入mysql,修改密码,授权远程登录

mysql -u root -p
set password=password('bj5m@0429!@#');
flush privileges;
UPDATE `mysql`.`user` SET `Host` = '%', `User` = 'root' WHERE (`Host` = 'localhost') AND (`User` = 'root');
grant all privileges on *.* to 'root'@'%'  identified by 'bj5m@0429!@#';
flush privileges;

你可能感兴趣的:(开发环境,linux)