https://dev.mysql.com/downloads/mysql/5.7.html#downloads
(1).通过Xftp上传至/usr/local/software
(2).解压
[root@localhost software]# tar -zxvf mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz
(3)解压后由于文件夹名太长,为其重命名为 mysql(目录结构为 /usr/local/mysql)
[root@localhost software]# mv mysql-5.7.27-linux-glibc2.12-x86_64 mysql
[root@localhost software]# mv mysql /usr/local/
[root@localhost local]# rpm -qa | grep mysql
如果显示出 mysql-xx 什么的,对其删除,指令为:rpm -e --nodeps 显示出来的文件名,接着检查 mariadb
[root@localhost local]# rpm -qa | grep mariadb
同样,若是显示 mariadb-xx ,也对其删除,指令同上
[root@localhost local]# groupadd mysql
[root@localhost local]# useradd -r -g mysql mysql
[root@localhost local]# chown -R mysql mysql
[root@localhost local]# chgrp -R mysql mysql
[root@localhost local]# cd mysql/
[root@localhost mysql]# vi /etc/my.cnf
[mysqld]
port=3306
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
user=mysql
tmpdir=/tmp
bind-address = 0.0.0.0
max_connections=200
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
default-storage-engine=INNODB
innodb_buffer_pool_size=64MB
max_allowed_packet=16M
skip-name-resolve
[mysqld_safe]
log-error=/usr/local/mysql/data/error.log
pid-file=/usr/local/mysql/data/mysql.pid
[mysql]
default-character-set=utf8mb4
[client]
socket=/tmp/mysql.sock
default-character-set=utf8mb4
(1)先安装个 libaio(有的虚拟机可能已经有了这个,反正执行一次不亏)
[root@localhost mysql]# yum -y install libaio
(2)创建 data 目录(按照上面的配置目录)
[root@localhost mysql]# mkdir data
(3)初始化(mysql目录 /usr/local/mysql ,重点是复制记住初始化生成的密码)
[root@localhost mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
(1)把 mysql.server 复制到 init.d/mysql 下(init.d下无mysql 文件夹也无妨,直接执行下面这句)
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql
(2)添加可执行权限(这步可以不执行,直接走第三部)
[root@localhost mysql]# chmod +x /etc/init.d/mysql
(3)添加 mysql 服务
[root@localhost mysql]# chkconfig --add mysql
(4)查看服务列表(若 3 4 5 为 off,则执行:chkconfig --level 345 mysql on)
[root@localhost mysql]# chkconfig --list
[root@localhost mysql]# vi /etc/profile
后面补上下面两句后再执行 source /etc/profile 使配置立即生效
export MYSQL_HOME=/usr/local/mysql
export PATH=$MYSQL_HOME/bin:$PATH
[root@localhost mysql]# source /etc/profile
(1)命令启动
[root@localhost mysql]# service mysql start
[root@localhost mysql]# ./bin/mysql -u root -p
(3)修改密码(注意:在 mysql> 后输入的命令末尾要加分号;我的密码就设为 root,随意;第二句要对应所设的密码)
set password=password('root');
grant all privileges on *.* to root@'%' identified by 'root';
flush privileges;
(4)设置远程访问权限(执行完后,输入 quit 即可退出,退出可不加分号)
use mysql;
update user set user.Host='%' where user.User='root';
select host from user where user = 'root';
flush privileges;
[root@localhost mysql]# service mysql restart
主要命令
启动: service mysql start
关闭: service mysql stop
状态: service mysql status