CentOS7离线安装Mysql8.0.18
查询出来已安装的mariadb
rpm -qa|grep mariadb
卸载mariadb,文件名为上述命令查询出来的文件
rpm -e --nodeps 文件名
上传安装包到/opt目录
解压安装包
tar Jxvf mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz
重命名
mv mysql-8.0.18-linux-glibc2.12-x86_64 mysql
mv mysql /usr/local
创建数据目录
mkdir /usr/local/mysql/data
创建并编辑my.cnf文件
vim /etc/my.cnf
填入以下内容
[client]
port=3306
socket=/tmp/mysql.sock
[mysqld]
port=3306
user=mysql
socket=/tmp/mysql.sock
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
log-error=/usr/local/mysql/error.log
pid-file = /usr/local/mysql/mysql.pid
transaction_isolation = READ-COMMITTED
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
lower_case_table_names = 1
sql_mode = "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO"
创建组
groupadd mysql
创建用户
useradd -g mysql mysql
修改目录权限
- 将 /opt/mysql给予mysql用户
chown -R mysql:mysql /usr/local/mysql
- 将/opt/mysql权限设置为755
chmod -R 755 /usr/local/mysql
初始化mysql
cd /usr/local/mysql
./bin/mysqld --initialize --user=mysql
尝试启动mysql
cd /usr/local/mysql
./support-files/mysql.server start
启动成功则如下:
将mysql添加为服务
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
设置开机启动
cd /etc/init.d
chmod 755 /etc/init.d/mysql
chkconfig --add mysql
chkconfig --level 345 mysql on
service mysql restart
配置环境变量
echo 'export MYSQL_HOME=/usr/local/mysql' >> /etc/profile
echo 'export PATH=.:$MYSQL_HOME/bin:$PATH' >> /etc/profile
source /etc/profile
使用默认密码登录mysql
在mysql目录下有一个error.log的文件,打开可以看到默认密码
mysql -uroot -p(默认密码)
在MySQL8中第一次登陆需要重新设置root密码
ALTER user 'root'@'localhost' IDENTIFIED BY '123456';
开启远程访问
CREATE USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456'; GRANT ALL ON *.* TO 'root'@'%';
FLUSH PRIVILEGES;
以上操作完,可以去远程客户端登录访问