-
安装说明
- 采用二进制安装
- MySQL安装规范:软件和数据分开
- 软件安装目录:/usr/local/mysql
- 数据目录:/data/mysql/mysql_3306
- 数据:/data/mysql/mysql_3306/data
- 日志:/data/mysql/mysql_3306/logs
- tmp:/data/mysql/mysql_3306/tmp
-
安装过程
-
1.安装系统依赖包
yum install gcc gcc-c++ openssl openssl-devel libaio libaio-devel ncurses ncurses-devel
-
2.下载MySQL8社区版 安装包
- 下载地址:https://dev.mysql.com/downloads/mysql/
- 下载地址:https://dev.mysql.com/downloads/mysql/
-
3.解压tar包,并移至安装目录
-
将下载完成的mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz包通过Xftp或者拖到Linux平台的src目录(/usr/local/src),如下:
- 使用拖动功能,需安装:yum install lrzsz -y
- 使用拖动功能,需安装:yum install lrzsz -y
-
解压:
tar -Jxvf mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz
-
将解压后的文件移到到软件安装目录
mv mysql-8.0.19-linux-glibc2.12-x86_64 /usr/local/mysql
-
环境变量设置
- 将export PATH=$PATH:/usr/local/mysql/bin 配置到/etc/profile中
-
执行以下命令,使配置生效
source /etc/profile
-
测试安装:mysql -V
-
-
4.配置启动脚本
- 配置mysql.server,位置如下:
- /usr/local/mysql/support-files/mysql.server
- 配置内容,安装目录和数据目录
- basedir=/usr/local/mysql
- datadir=/data/mysql/mysql_3306/data
- 复制启动脚本至/etc/init.d下
- cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
- 配置mysql.server,位置如下:
-
5.创建账号和目录
- 创建MySQL相应的目录
mkdir -p /data/mysql/mysql_3306/{data,logs,tmp}
- 创建账号并授权
useradd mysql -s /sbin/nologin chown -R mysql:mysql /data/mysql/mysql_3306 /usr/local/mysql/
- 创建MySQL相应的目录
-
6.配置my.cnf
-
创建并配置my.cnf, 位置:/etc/my.cnf
-
my.cnf模板
[root@localhost etc]# cat my.cnf [mysqld] #bind-address=127.0.0.1 192.168.133.1 port=3306 character-set-server=utf8mb4 datadir=/data/mysql/mysql_3306/data user=mysql skip-name-resolve slow_query_log=1 long_query_time=0.2 slow_query_log_file=/data/mysql/mysql_3306/logs/mysql-slow.log innodb-file-per-table=1 innodb_flush_log_at_trx_commit=2 max_allowed_packet=512M connect_timeout=60 net_read_timeout=120 [client] default-character-set=utf8mb4 [mysqld_safe] log-error=/data/mysql/mysql_3306/logs/mysqld.log pid-file=/data/mysql/mysql_3306/mysqld.pid
-
-
7.MySQL数据的初始化
-
执行如下命令
mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/mysql_3306/data
-
初始化后,请记住生成的root密码
[root@localhost local]# mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/mysql_3306/data 2020-04-05T02:43:03.783643Z 0 [System] [MY-013169 ] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.19 ) initializing of server in progress as process 41728 2020-04-05T02:43:11.466634Z 5 [Note] [MY-010454] [ Server] A temporary password is generated for root@ localhost: #ky(tNmke0L.
-
验证是否初始化成功:查看/data/mysql/mysql_3306/data
-
-
8.启动Mysql服务器
脚本启动:/etc/init.d/mysqld start 脚本关闭:/etc/init.d/mysqld stop
-
9.登陆MySQL
[root@localhost ~]# mysql -uroot -p Enter password: 显示数据库:show databases; 创建数据库:create database XXX;
-
10.修改初始密码
alter user 'root'@'localhost' identified by '你的密码';
-
-
建议要求
-
Systemctl管理
- 配置目录
/usr/lib/systemd/system/mysqld.service
- 配置参数
[Unit] Description=mysqld After=network.target [Service] Type=forking ExecStart=/etc/init.d/mysqld start [Install] WantedBy=multi-user.target
- Systemctl管理MySQL
- 开机启动:systemctl enable mysqld
- 启动:systemctl start mysqld
- 关闭:systemctl stop mysqld
- 重启:systemctl restart mysqld
-
-
Q & A
- libncurses.so.5 未找到的问题
- 解决:
- 安装:dnf install ncurses-compat-libs
- 软连接:ln -s libtinfo.so.5 /usr/lib/libncurses.so.5.9
- 解决:
- 参考文章
- https://www.cnblogs.com/bjx2020/p/10682518.html
- libncurses.so.5 未找到的问题
CentOS8下安装MySQL8
最新推荐文章于 2024-08-29 12:02:24 发布