Centos7下MySQL5.7.22安装
su root
1.系统约定
安装文件下载目录:/data/software
Mysql目录安装位置:/usr/local/mysql
数据库保存位置:/data/mysql
日志保存位置:/data/log/mysql
2.安装文件下载目录
mkdir -p /data/software/
3.解压压缩包到目标位置
cd /data/software/
rz
tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
mv /data/software/mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql
4.创建数据仓库目录
mkdir -p /data/mysql
5.新建mysql用户、组及目录
groupadd mysql
useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/mysql
6.改变目录属有者
cd /usr/local/mysql
chown -R mysql .
chgrp -R mysql .
chown -R mysql /data/mysql
7.配置参数
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
##password:Vt#f,vyl2Xpd
bin/mysql_ssl_rsa_setup --datadir=/data/mysql
8.修改系统配置文件
cd /usr/local/mysql/support-files
cp mysql.server /etc/init.d/mysql
vi /etc/init.d/mysql
basedir=/usr/local/mysql
datadir=/data/mysql
注:mysql5.7.21不需要my.cnf文件
9.启动mysql
/etc/init.d/mysql start
注意:这个地方可能会启动报错,原因是centos7的/etc/目录下默认存在my.cnf文件,而mysql默认会根据这个配置文件启动,先将其删除即可
cd /etc/
mv my.cnf my.cnf.bak
再次启动
/etc/init.d/mysql start
10.登陆
mysql -h localhost -u root -p
--如果出现:-bash: mysql: command not found
--就执行: # ln -s /usr/local/mysql/bin/mysql /usr/bin --没有出现就不用执行
--输入第6步生成的临时密码
11.修改密码
mysql> set password=password('123456');
12.设置root账户的host地址(修改了才可以远程连接)
mysql>grant all privileges on *.* to 'root'@'%' identified by '123456';
mysql>flush privileges;
--查看表
mysql> use mysql;
mysql> select host,user from user;
13.防火墙放行3306端口
firewall-cmd --zone=public --query-port=3306/tcp
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
14.添加系统路径
echo 'export PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile
source /etc/profile
15.配置mysql自动启动
chmod 755 /etc/init.d/mysql
chkconfig --add mysql
chkconfig --level 345 mysql on
16.关闭mysql
/etc/init.d/mysql stop
17.查询最大连接数
mysqladmin -uroot -p variables |grep max_connections
18.优化
重写/etc/my.cnf 文件,重启mysql
================================================================================
附:my.cnf
[mysqld]
server-id = 1
port = 3306
character-set-server = utf8
collation-server = utf8_general_ci
init_connect=‘SET NAMES utf8‘
lower_case_table_names = 1
max_connections = 1500
max_connect_errors = 1000
explicit_defaults_for_timestamp = true
#datadir=/var/lib/mysql
#socket=/var/lib/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]
#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
参考资料:
https://dev.mysql.com/doc/refman/5.7/en/replication-howto-masterbaseconfig.html