检查是否安装了mysql
rpm -qa | grep mysql
如有,类似
mysql-libs-5.1.52-1.el6_0.1.x86_64
卸载之
rpm -e --nodeps mysql-libs-5.1.52.x86_64
检查否存在 mariadb 数据库,如有,卸载之,卸载同上
rpm -qa | grep mariadb
查看linux系统是64位还是32位
getconf LONG_BIT
到mysql官网下载安装包(64位)
mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
上传安装包至/usr/local,解压安装包
cd /usr/local
tar -zvxf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz mysql-5.7.25
创建data目录
cd mysql-5.7.25
mkdir data
检查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用户是系统用户,不可用于登录系统
将/usr/local/mysql-5.7.25的所有者及所属组改为mysql
chown -R mysql.mysql /usr/local/mysql-5.7.25
在/usr/local/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
basedir = /usr/local/mysql-5.7.25
datadir = /usr/local/mysql-5.7.25/data
port = 3306 socket = /tmp/mysql.sock
character-set-server=utf8
log-error = /usr/local/mysql-5.7.25/data/mysqld.log
pid-file = /usr/local/mysql-5.7.25/data/mysqld.pid
拷贝
cp support-files/my_default.cnf /etc/my.cnf
初始化 mysqld
cd /usr/local/mysql-5.7.25/bin
./mysqld --initialize --user=mysql --basedir=/usr/local/mysql-5.7.25/ --datadir=/usr/local/mysql-5.7.25/data/
初始化完成之后,查看日志
/usr/local/mysql-5.7.25/data/mysqld.log
临时密码
[Note] A temporary password is generated for root@localhost: i8r#tnAuaanT
把启动脚本放到开机初始化目录
cp support-files/mysql.server /etc/init.d/mysql
启动mysql服务
service mysql start
查看mysql进程
ps -ef | grep mysql
登录mysql,密码为初始密码
cd /usr/local/mysql-5.7.25/bin
./mysql -u root -p
修改密码
mysql> set password=password('root');
mysql> grant all privileges on *.* to root@'%' identified by 'root';
//执行之后如果出现下面ERROR,可不用理会
ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY'
mysql> flush privileges;
添加远程访问权限
mysql> use mysql;
mysql> update user set host='%' where user = 'root';
mysql> flush privileges;
重启mysql生效
service mysql restart