#检查是否安装mysql
rpm -qa | grep mysql
#卸载
pm -e --nodeps mysql.x86_64
#下载,解压
tar -zxvf mysql.tar.gz
#检查是否存在mysql组和用户
cat /etc/group | grep mysql
#添加mysql组和用户
groupadd mysql
useradd -r -g mysql mysql
#创建数据目录
mkdir data
#赋权给mysql
chown -R mysql.mysql /opt/module/mysql7/
#在support-files/里面创建my_default.cnf
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
basedir = /opt/module/mysql7
datadir = /opt/module/mysql7/data
port = 3306
socket = /tmp/mysql.sock
character-set-server=utf8
log-error = /opt/module/mysql7/data/mysqld.log
pid-file = /opt/module/mysql7/data/mysqld.pid
#覆盖/etc/my.cnf
cp my_default.cnf /etc/my.cnf
#初始化,如果报错bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory 执行yum install -y libaio
./mysqld --initialize --user=mysql --basedir=/opt/module/mysql7/ --datadir=/opt/module/mysql7/data/
#把启动脚本放到开机初始化目录
cp support-files/mysql.server /etc/init.d/mysql
#启动
service mysql start
#查看随机密码
vim data/mysqld.log
#登录mysql
bin/mysql -u root -p
#修改密码
mysql> set password=password('123456');
mysql> grant all privileges on *.* to root@'%' identified by '123456';
mysql> flush privileges;
#添加远程访问权限
mysql> use mysql;
mysql> update user set host='%' where user = 'root';
#把后三条删除,没有忽略
mysql> select host,user from user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| % | root |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+---------------+
delete from user where host = 'localhost';
mysql> flush privileges;
#重启
service mysql restart
linux安装MySQL5.7
最新推荐文章于 2024-08-05 17:44:45 发布