第一步:下载linux版本的mysql
下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads
我这里下载mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz版本
第二步:安装配置
1、查看linux是否安装有mysql
rpm -qa | grep mysql
如有,类似
mysql-libs-5.1.52-1.el6_0.1.x86_64
删除
rpm -e mysql-libs-5.1.52-1.el6_0.1.x86_64 // 普通删除模式
rpm -e --nodeps mysql-libs-5.1.52-1.el6_0.1.x86_64 // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除
检查否存在 mariadb 数据库,如有,卸载之,卸载同上
2、上传mysql安装包到华为云服务器
3、安装mysql
解压安装包
tar -zxvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
4、添加系统mysql组和mysql用户
cat /etc/group | grep mysql
#类似
mysql:x:490:
cat /etc/passwd | grep mysql
#类似
mysql:x:496:490::/home/mysql:/bin/bash
以上为存在的情况,如无,执行添加命令
groupadd mysql
useradd -r -g mysql mysql
#useradd -r参数表示mysql用户是系统用户,不可用于登录系统
5、配置mysql
cd mysql-5.7.25
mkdir data
6、将/opt/mysql/mysql-5.7.25的所有者及所属组改为mysql
chown -R mysql.mysql /opt/mysql/mysql-5.7.25
7、在/opt/mysql/mysql-5.7.25/support-files目录下创建my_default.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#填写自己的mysql地址
basedir = /opt/mysql/mysql-5.7.25
datadir = /opt/mysql/mysql-5.7.25/data
port = 3306
socket = /tmp/mysql.sock
character-set-server=utf8
log-error = /opt/mysql/mysql-5.7.25/data/mysqld.log
pid-file = /opt/mysql/mysql-5.7.25/data/mysqld.pid
8、拷贝,如果提示是否覆盖,y
cp support-files/my_default.cnf /etc/my.cnf
9、初始化 mysqld
cd /opt/mysql/mysql-5.7.25
./bin/mysqld --initialize --user=mysql --basedir=/opt/mysql/mysql-5.7.25/ --datadir=/opt/mysql/mysql-5.7.25/data/
10、初始化完成,查看日志
/opt/mysql/mysql-5.7.25/data/mysqld.log
11、临时密码
2019-04-08T06:14:29.790033Z 1 [Note] A temporary password is generated for root@localhost: a8?DQir=T+k+
12、设置开机自启动
cp support-files/mysql.server /etc/init.d/mysql
13、启动mysql服务
service mysql start
14、登录mysql,密码为初始密码
cd /opt/mysql/mysql-5.7.25
./bin/mysql -u root -p
15、修改密码
mysql> set password=password('123456');
mysql> grant all privileges on *.* to root@'%' identified by '123456';
mysql> flush privileges;
16、添加远程访问权限
mysql> use mysql;
mysql> update user set host='%' where user = 'root';
mysql> flush privileges;
17、重启mysql生效
service mysql stop
service mysql start
或者
service mysql restart