查看数据库排名:db-engines.com
3. 软件的获取和安装
https://downloads.mysql.com/
https://dev.mysql.com/downloads/mysql/
3.1 解压
[root@db01 opt]# tar xf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
3.2 做软连接
[root@db01 opt]# ln -s /opt/mysql-8.0.20-linux-glibc2.12-x86_64 /usr/local/mysql
3.3 环境变量
[root@db01 mysql]# vim /etc/profile
export PATH=/usr/local/mysql/bin:$PATH
[root@db01 mysql]# source /etc/profile
3.4 清理环境
[root@db01 mysql]# rpm -qa|grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
[root@db01 mysql]# yum remove -y mariadb-libs
[root@db01 mysql]# ls -l /etc/my.*
3.5 创建用户
[root@db01 mysql]# useradd mysql
3.6 创建数据目录并授权
[root@db01 mysql]# mkdir -p /data/3306/data
[root@db01 mysql]# chown -R mysql.mysql /data
3.7 初始化数据
[root@db01 mysql]# yum install -y libaio-devel
[root@db01 mysql]# mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/3306/data
2020-11-22T02:20:34.000735Z 0 [System] [MY-013169] [Server] /opt/mysql-8.0.20-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.20) initializing of server in progress as process 18295
2020-11-22T02:20:34.031634Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-11-22T02:20:35.308311Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-11-22T02:20:36.876260Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
[root@db01 mysql]#
报错可能:
A.
--initialize specified but the data directory has files in it. Aborting.
解决:
rm -fr 删除目录下的数据再初始化
B.
缺失 libaio-....
yum install -y libaio-devel
彩蛋:
a. 不同版本初始化方式区别
5.7 之前版本:
/usr/local/mysql56/scripts/mysql_install_db --.....
5.7 之后版本:
mysqld --initialize-insecure
b. --initialize-insecure 和 --initialize
不带-insecure:
初始化后,管理用户(root@'localhost')生成一个12位,4种密码复杂度临时密码.
临时密码登陆后,需要重置管理用户密码,否则没法做任何操作.
3.8 配置文件
[root@db01 ~]# vim /etc/my.cnf
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/data/3306/data
socket=/tmp/mysql.sock
port=3306
[clinet]
socket=/tmp/mysql.sock
3.9 启动脚本准备
[root@db01 ~]# cd /usr/local/mysql/support-files/
[root@db01 support-files]# ./mysql.server start
Starting MySQL.Logging to '/data/3306/data/db01.err'.
. SUCCESS!
[root@db01 support-files]# cp mysql.server /etc/init.d/mysqld
# sys-V
[root@db01 ~]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL.. SUCCESS!
# systemd
[root@db01 ~]# systemctl enable mysqld
mysqld.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig mysqld on
[root@db01 ~]# systemctl restart mysqld
[root@db01 ~]# systemctl stop mysqld
[root@db01 ~]# systemctl start mysqld
3.10 连接测试
[root@db01 ~]# mysql
有问题请加博主微信进行沟通!
全部评论