下载mysql-5.7.24的mysql的repo源,此yum源自动下载最新版本。
下载完成后执行安装
wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpmrpm -ivh mysql57-community-release-el7-8.noarch.rpmyum -y install mysql-server
安装完成后
修改my.cnf文件
vim /etc/my.cnf[mysqld]## Remove leading # and set to the amount of RAM for the most important data# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.# innodb_buffer_pool_size = 128M## Remove leading # to turn on a very important data integrity option: logging# changes to the binary log between backups.# log_bin## Remove leading # to set options mainly useful for reporting servers.# The server defaults are faster for transactions and fast SELECTs.# Adjust sizes as needed, experiment to find the optimal values.# join_buffer_size = 128M# sort_buffer_size = 2M# read_rnd_buffer_size = 2Mdatadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sock# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid# 设置密码安全策略为0,低等级validate_password_policy=0# 设置编码character_set_server=utf8init_connect='SET NAMES utf8'# 忽略表名大小写lower_case_table_names=1skip-name-resolve
[可选项 start]
执行mysqld --initialize 初始化
如果遇到 unknown variable 'validate_password_policy=0' 错误,在my.cnf中将这个变量注释掉
如果遇到 The innodb_system data file 'ibdata1' must be writable 错误,执行此命令给mysql data文件夹赋予读写权限 chmod -R 777 /var/lib/mysql
[可选项 end]
使用 systemctl start mysqld 启动mysql服务
使用 grep 'password' /var/log/mysqld.log 获取mysql初始密码
使用刚刚获取的初始密码登录 mysql -uroot -p
更改新密码 set password for root@localhost = password('your password');
创建新用户,授权,刷新权限
grant privileges ON databasename.tablename to 'username'@'host' idendified by 'password';flush privileges;
PS.设置mysql自启动
systemctl enable mysqldsystemctl enable daemon-reload
