1 安装MySQL
1.1 下载对应文件
mysql-5.7.36-1.el7.x86_64.rpm-bundle.tar
1.2 检查系统是否自带Mysql
rpm -qa | grep mysql
#如果有,删除掉
rpm -e --nodeps mysql的名称
1.3 检查是否自带mariadb
rpm -qa | grep mariadb
#有就删除掉
rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
1.4 解压mysql5.7并指定目录/usr/local/mysql/
tar -xvf mysql-5.7.36-1.el7.x86_64.rpm-bundle.tar -C /usr/local/mysql/
1.5 安装依赖库
yum install -y libaio
yum install -y net-tools
yum -y install perl perl-devel
1.6 进入解压目录/usr/local/mysql/,按顺序安装mysql
rpm -ivh mysql-community-common-5.7.36-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.36-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.36-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.36-1.el7.x86_64.rpm
2 设置远程访问
2.1 初始化数据库
mysqld --initialize --user=mysql
mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --initialize
初始化密码文件位置:cat /var/log/mysqld.log
2.2 安装mysql后登录提示:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password:yes)
# 停止mysql服务
systemctl stop mysqld.service
- 修改配置文件无密码登录
vi /etc/my.cnf
#在最后加上
skip-grant-tables
- 启动mysql服务
systemctl start mysqld.service
- 修改密码,mysql5.7用此语法
#第一次登录,需要修改默认密码,使用命令
mysql> SET PASSWORD = PASSWORD('123456');
mysql> use mysql;
mysql> update mysql.user set authentication_string=password('123456') where user='root' ;
mysql> select Host,User from mysql.user;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%'IDENTIFIED BY 'admin' WITH GRANT OPTION;
#使用配置立即生效
mysql> flush privileges;
删除 /etc/my.cnf文件末尾skip-grant-tables
网友评论