MySQL离线安装文档(Linux版)
安装包:
mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz
系统:
CentOS Linux 7 (64位)
操作说明
- 把安装包上传到/usr/local目录下,解压安装包
[root@localhost local]# tar -xvJf mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz
- 重命名,便于操作
[root@localhost local]# mv mysql-8.0.27-linux-glibc2.12-x86_64 mysql-8.0
- 在mysql-8.0下创建data文件夹,放置数据文件
- 创建用户组以及用户和密码
[root@localhost mysql-8.0]# groupadd mysql
[root@localhost mysql-8.0]# useradd -g mysql mysql
- 给用户授权
[root@localhost mysql-8.0]# chown -R mysql.mysql /usr/local/mysql-8.0
- 进入bin目录下,初始化基础信息 。记录初始密码,之后要用
[root@localhost bin]# ./mysqld --user=mysql --basedir=/usr/local/mysql-8.0 --datadir=/usr/local/mysql-8.0/data/ --initialize
- 添加mysqld服务到系统
[root@localhost mysql-8.0]# cp -a ./support-files/mysql.server /etc/init.d/mysql
- 授权以及添加服务
[root@localhost mysql-8.0]# chmod +x /etc/init.d/mysql
[root@localhost mysql-8.0]# chkconfig --add mysql
- 启动mysql
[root@localhost mysql-8.0]# service mysql start
- 1查看启动状态
[root@localhost mysql-8.0]# service mysql status
- 将mysql命令添加到服务
[root@localhost mysql-8.0]# ln -s /usr/local/mysql-8.0/bin/mysql /usr/bin
- 登录mysql mysql -uroot -p 密码使用之前随机生成的初始密码
[root@localhost mysql-8.0]# mysql -uroot -p
Enter password:
- 修改root密码 其中123456是新的密码自己设置
mysql> ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘Nreal0125@’;
[图片]
- 执行flush privileges;使密码生效
mysql> flush privileges;
- 选择mysql数据库
mysql> use mysql
- 修改root用户的IP限制并生效(根据需求调整)
host=‘%’:指不限制IP,host=‘localhost’:只能本地登陆
[图片]
可能遇到的问题
- service mysql start启动失败
解决方案:修改/etc/my.cnf,样例如下
[mysqld]
basedir=/usr/local/mysql-8.0
datadir=/usr/local/mysql-8.0/data
socket=/tmp/mysql.sock
character-set-server=UTF8MB4
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/var/log/mysql.log
pid-file=/usr/local/mysql-8.0/data/mysql.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d