Centos7.x 安装MYSQL
# 安装依赖包
yum -y install libaio
# 创建mysql 用户组和用户
groupadd mysql
useradd -g mysql mysql
# 创建需要文件夹和文件
mkdir -p /usr/local/resources/mysql-5.7.27/{data,log,etc,run}
touch /usr/local/resources/mysql-5.7.27/log/{mysql_error.log,mysql_bin.log,mysql_slow_query.log}
chown -R mysql:mysql /usr/local/resources/mysql-5.7.27
chmod 750 /usr/local/resources/mysql-5.7.27/{data,log,etc,run}
# 配置环境变量
export MYSQL_HOME=/usr/local/resources/mysql-5.7.27
export PATH=.:$MYSQL_HOME/bin:$PATH
# 配置/etc/my.cnf文件
[client]
port = 3306
socket = /usr/local/resources/mysql-5.7.27/run/mysql.sock
[mysqld]
port = 3306
socket = /usr/local/resources/mysql-5.7.27/run/mysql.sock
pid_file = /usr/local/resources/mysql-5.7.27/run/mysql.pid
datadir = /usr/local/resources/mysql-5.7.27/data
default_storage_engine = InnoDB
max_allowed_packet = 128M
max_connections = 2048
open_files_limit = 65535
skip-name-resolve
lower_case_table_names=1
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
innodb_buffer_pool_size = 128M
innodb_log_file_size = 128M
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit = 0
key_buffer_size = 16M
log-error = /usr/local/resources/mysql-5.7.27/log/mysql_error.log
log-bin = /usr/local/resources/mysql-5.7.27/log/mysql_bin.log
slow_query_log = 1
slow_query_log_file = /usr/local/resources/mysql-5.7.27/log/mysql_slow_query.log
long_query_time = 5
tmp_table_size = 16M
max_heap_table_size = 16M
query_cache_type = 0
query_cache_size = 0
server-id=1
# 初始化MYSQL
mysqld --initialize --user=mysql --basedir=/usr/local/resources/mysql-5.7.27 --datadir=/usr/local/resources/mysql-5.7.27/data
# 此时会生成一个root的临时密码,默认在mysql_error.log文件中
grep 'temporary password' /usr/local/resources/mysql-5.7.27/log/mysql_error.log
# 注:有可能并没有写进文件,直接在执行后的界面显示
# 配置服务
cp /usr/local/resources/mysql-5.7.27/support-files/mysql.server /etc/init.d/mysqld
# 修改/etc/init.d/mysqld文件
vim /etc/init.d/mysqld
# 修改basedir和datadir参数值
basedir = /usr/local/resources/mysql-5.7.27
datadir = /usr/local/resources/mysql-5.7.27/data
# 添加服务
chkconfig --add mysqld
# 设置开机自启和查看
chkconfig mysqld on
chkconfig mysqld --list
# 启动服务
service mysqld start
# 查看服务状态
service mysqld status
# 注意: 如果是Centos8安装的话, 需要添加以下语句
ln -s /usr/lib64/libtinfo.so.6 /usr/lib64/libtinfo.so.5
ln -s /usr/lib64/libncurses.so.6 /usr/lib64/libncurses.so.5
# 修改root账户密码
mysql -u root -p 初始化临时密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
flush privileges;
exit;
# 重新登录mysql验证
# 修改全网登录配置
use mysql;
update user set host='%' where host='localhost';
flush privileges;
quit;