环境
系统:CentOS 7.8
软件:mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
安装
-
创建MySQL用户
# useradd mysql
-
解压二进制包
# tar -xzvf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz # mv mysql-5.7.31-linux-glibc2.12-x86_64 /usr/local/mysql
-
配置环境变量
# vim /etc/profile export PATH=/usr/local/mysql/bin:$PATH # source /etc/profile
配置
-
配置my.cnf
# mkdir /usr/local/mysql/etc # touch /usr/local/mysql/etc/my.cnf # ln -sf /usr/local/mysql/etc/my.cnf /etc/ # vim /etc/my.cnf [mysqld_safe] log-error=/usr/local/mysql/log/mysql.err [mysqld] datadir=/usr/local/mysql/data tmpdir=/usr/local/mysql/tmp socket=/usr/local/mysql/run/mysql.sock user=mysql character_set_server=utf8mb4 default-storage-engine=INNODB innodb_buffer_pool_size=1G slow_query_log=1 slow_query_log_file=/usr/local/mysql/log/mysql.slow long_query_time=2 server_id=1 log-bin=/usr/local/mysql/log-bin/log-bin binlog_format=row max_connections=1000 [client] socket=/usr/local/mysql/run/mysql.sock
-
配置数据和日志目录
# mkdir -p /data/mysql/{data,log,log-bin,run,tmp} # ln -s /data/mysql/{data,log,log-bin,run,tmp} /usr/local/mysql/ # touch /usr/local/mysql/log/mysql.err # chown -R mysql:mysql /data/mysql # chown -R mysql:mysql /usr/local/mysql
-
初始化
# mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data ...... A temporary password is generated for root@localhost: ttwg%gBw*4uo
记录生成的临时密码
启动
-
启动
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld # chkconfig --add mysqld # chkconfig mysqld on # /etc/init.d/mysqld restart
-
运行安全配置向导
# mysql_secure_installation -S /usr/local/mysql/run/mysql.sock Enter password for user root: 输入刚才的临时密码 New password: Re-enter new password: Press y|Y for Yes, any other key for No: n Change the password for root ? ((Press y|Y for Yes, any other key for No) : no Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
网友评论