mysql 8.0安装配置(yum安装,二进制免编译安装)
1、检查安装,清除环境
检查是否安装MySQL,有则卸载
rpm -qa | grep mysql
rpm -qa | grep mariadb
rpm -e --nodeps mysql
-e 卸载
--nodeps 忽略依赖卸载,强力删除模式
查找与MySQL相关的残留目录
find / -name mysql 或者 whereis mysql
全部删除相应文件目录
删除MySQL配置文件
rm -rf /etc/my.cnf
rm -rf /etc/init.d/mysqld
删除mysql用户及用户组
#id mysql
uid=27(mysql) gid=27(mysql) 组=27(mysql)
# userdel mysql
2、安装
2.1 yum安装Mysql 8.0
1.下载mysql的yum仓库
[root@xingdian-mysql-1 /]# wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
2.安装mysql的yum仓库
[root@xingdian-mysql-1 /]# rpm -ivh mysql80-community-release-el7-3.noarch.rpm
3.安装数据库
[root@xingdian-mysql-1 /]# yum -y install mysql-server mysql
4.指定MySQL存放数据的目录
[root@localhost home]# mkdir mysql_data
[root@localhost home]# chown -R mysql.mysql mysql_data
# vim /etc/my.cnf
datadir=/home/mysql_data
5.查看数据库的初始密码
[root@localhost ~]# systemctl start mysqld
[root@xingdian-mysql-1 /]# grep 'password' /var/log/mysqld.log
2019-07-13T15:14:31.176905Z 1 [Note] A temporary password is generated for root@localhost:k12zPB1r;2Ta
5.修改数据库密码
[root@xingdian-mysql-1 /]# mysqladmin -u root -p'旧密码' password'Litaimin@123'
密码:大小写有特殊字符数字
5.7版本yum安装:https://blog.csdn.net/qq_36582604/article/details/80526287
2.2 二进制免编译安装
1.添加mysql用户和用户组
#useradd -U -M -s /sbin/nologin mysql
2.创建目录放置mysql安装目录,数据目录,日志目录
#mkdir /home/mysql_8
#mkdir /home/mysql_8/data
#mkdir /home/mysql_8/logs
3.下载压缩包并解压到相应用户
#wget https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz
#tar -xf mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz -C /home/mysql_8/mysql
#chown -R mysql.mysql /home/mysql_8/
3.添加环境相应环境变量
#vim /etc/profile
...
export PATH=$PATH:/home/mysql_8/mysql/bin
# source /etc/profile
4.进行数据库初始化
#mysqld --initialize --user=mysql --datadir=/home/mysql_8/data --basedir=/home/mysql_8/mysql
5.添加配置文件(要与初始化的数据一致,否则启动会报错)
#vim /etc/my.cnf
[mysqld]
basedir=/home/mysql_8/mysql
datadir=/home/mysql_8/data
port=3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=600
innodb_file_per_table=1
log-error=/home/mysql_8/logs/error.log
6.启动(初始密码在日志里面)
# /home/mysql_8/mysql/support-files/mysql.server start
#mysql -uroot -p'password'
7.添加服务(service),还有开机自启
#cp /home/mysql_8/mysql/support-files/mysql.server /etc/init.d/mysqld
#chmod +x /etc/init.d/mysqld
#chkconfig --add mysqld
#chkconfig --list
常见启动报错
情况1:error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
#yum install libncurses* //解决相关版本依赖问题
情况2:ERROR! The server quit without updating PID file (/home/mysql_8/data/localhost.localdomain.pid).
删除data目录下的内容,重新初始化 注意:此方法仅供安装使用,如有重要数据请谨慎操作!!!!!!