安装 MySQL5.6
下载 MySQL 8.0.xx
https://downloads.mysql.com/archives/community/
选择操作系统为 Linux-Generic
下载 .tar.xz 文件
传输文件到 /app/mysql
,进行解压
[root@centos7 ~]# cd /app/mysql
[root@centos7 mysql]# tar -xvJf mysql-8.0.29-linux-glibc2.12-x86_64.tar.xz
[root@centos7 mysql]# mv mysql-8.0.30-linux-glibc2.12-x86_64 mysql-8
安装MySQL
创建一个mysql用户:
[root@centos7 mysql]# useradd mysql
设置mysql用户密码:
[root@centos7 mysql]# echo '123456'|passwd --stdin mysql
更改用户 mysql 的密码 。
passwd:所有的身份验证令牌已经成功更新。
进入到mysql的bin目录下 新建data,log文件夹
[root@centos7 mysql]# cd mysql-8
[root@centos7 mysql-8]# mkdir data
[root@centos7 mysql-8]# mkdir log
[root@centos7 mysql-8]# chown -R root:root ./
[root@centos7 mysql-8]# chown -R mysql:mysql data
[root@centos7 mysql-8]# chown -R mysql:mysql log
建立mysql软链接
[root@centos7 mysql-8]# rm -rf /usr/bin/mysql
[root@centos7 mysql-8]# ln -s /app/mysql/mysql-8/bin/mysql /usr/bin/mysql
复制 /etc/init.d/mysql 配置文件
[root@centos7 mysql-8]# rm -rf /etc/init.d/mysql
[root@centos7 mysql-8]# cp support-files/mysql.server /etc/init.d/mysql
然后在/etc/init.d/mysql 中配置
[root@centos7 mysql-8]# vi /etc/init.d/mysql
添加两行,就是mysql安装目录和目录下data
basedir=/app/mysql/mysql-8
datadir=/app/mysql/mysql-8/data
新建 /etc/my.cnf - 该文档来源于 mysql-5.6.30/support-files/my-default.cnf
[root@centos7 mysql]# rm -f /etc/my.cnf
[root@centos7 mysql]# vi /etc/my.cnf
设置数据存放目录,日志存储目录
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/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]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
basedir = /app/mysql/mysql-8
datadir = /app/mysql/mysql-8/data
character-set-server = UTF8MB4
port = 3306
# server_id = .....
# socket = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
log_error = /app/mysql/mysql-8/log/error.log
按 [command+c]
输入 :wq
初始化 mysqld
[root@centos7 mysql-8]# cd bin
[root@centos7 bin]# ./mysqld --initialize --console --user=mysql --basedir=/app/mysql/mysql-8 --datadir=/app/mysql/mysql-8/data
此时在 /app/mysql/mysql-8/log
中存在 error.log
里面存放着mysql登录的初始密码
[Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 0?z0<n#6qbU5
启动mysql服务
[root@centos7 mysql-8]# service mysql start
Starting MySQL. [ OK ]
系统控制mysql
# 启动mysql命令
service mysql start
#关闭mysql命令
service mysql stop
#查看运行状态命令
service mysql status
修改密码
输入的是刚刚的密码 0?z0<n#6qbU5
[root@centos7 mysql-8]# mysql -uroot -p
Enter password:
执行修改密码的命令
mysql> alter user 'root'@'localhost' identified by '密码';
Query OK, 0 rows affected (0.01 sec)
配置远程访问
mysql> create user 'root'@'%' identified by '密码';
Query OK, 0 rows affected (0.02 sec)
mysql> grant all on *.* to 'root'@'%';
Query OK, 0 rows affected (0.01 sec)
现在可以通过 Navicat 连接 ecs