【运维工程师学习】Centos8中MySQL替换MariaDB
- 1、查看已有的mysql
- 2、MySQL官网tar包下载
- 3、找到下载路径解压
- 4、移动解压后的文件夹到/usr/local/mysql
- 5、创建data文件夹,一般用于存放数据库文件数据
- 6、创建用户组
- 7、更改用户文件夹权限
- 8、生成my.cnf文件
- 9、编辑my.cnf
- 10、再次更改用户文件夹权限
- 11、初始化数据库
- 12、继续执行初始化数据库命令
- 13、查看初始化密码 日志文件在 `/usr/local/mysql/mysql.log`
- 14、修改配置,挨个执行,如果报错,跳过
- 15、修改环境变量,并重载环境变量文件
- 16、启动mysql
- 17、登录mysql,密码是上面的初始化密码
- 18、执行修改密码命令
- 19、mysql启动后,连接不上,不显示3306端口
- 20、授权远程访问
1、查看已有的mysql
rpm -qa | grep mysql
- 把搜索出来的全删除
rm -rf mysql-8.0.26-1.module_el8.4.0+915+de215114.x86_64
rm -rf mysql-server-8.0.26-1.module_el8.4.0+915+de215114.x86_64
rm -rf mysql-errmsg-8.0.26-1.module_el8.4.0+915+de215114.x86_64
rm -rf mysql80-community-release-el8-5.noarch
rm -rf mysql-common-8.0.26-1.module_el8.4.0+915+de215114.x86_64
- 查看路径里那里还有mysql
whereis mysql
- 全删除
rm -rf /usr/bin/mysql
rm -rf /usr/lib64/mysql
rm -rf /usr/share/mysql
rm -rf /usr/share/man/man1/mysql.1.gz
- 再找
find / -name mysql
- 再删
rm -rf /var/lib/selinux/targeted/active/modules/100/mysql
rm -rf /var/lib/selinux/targeted/tmp/modules/100/mysql
rm -rf /var/lib/mysql
rm -rf /var/lib/mysql/mysql
rm -rf var/log/mysql
rm -rf /var/log/mysql
rm -rf /usr/share/bash-completion/completions/mysql
rm -rf /usr/share/selinux/packages/mysql
rm -rf /usr/share/selinux/targeted/default/active/modules/100/mysql
2、MySQL官网tar包下载
MySQL官网tar包下载链接:https://dev.mysql.com/downloads/mysql/
wget https://dev.mysql.com/get/mysql-8.0.33-linux-glibc2.28-x86_64.tar.gz
3、找到下载路径解压
tar -zvxf mysql-8.0.33-linux-glibc2.28-x86_64.tar.gz
4、移动解压后的文件夹到/usr/local/mysql
mv mysql-8.0.33-linux-glibc2.28-x86_64 /usr/local/mysql
5、创建data文件夹,一般用于存放数据库文件数据
mkdir /usr/local/mysql/data
6、创建用户组
groupadd mysql;
useradd -g mysql mysql;
7、更改用户文件夹权限
chown -R mysql.mysql /usr/local/mysql/
8、生成my.cnf文件
touch /etc/my.cnf
9、编辑my.cnf
[mysql]
default-character-set=utf8
[mysqld]
port=3306
default_authentication_plugin=mysql_native_password
socket = /usr/local/mysql/mysql.sock
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data/
character-set-server=utf8
default-storage-engine=InnoDB
collation-server=utf8_unicode_ci
init_connect='SET NAMES utf8'
innodb_buffer_pool_size=512M
innodb_flush_log_at_trx_commit=0
innodb_lock_wait_timeout=31536000
innodb_log_buffer_size=8M
innodb_log_file_size=16M
join_buffer_size=200M
key_buffer_size=400M
log-error=/usr/local/mysql/mysql.log
pid-file=/usr/local/mysql/mysql.pid
log_error_verbosity=1
max_allowed_packet=2000M
max_connections=1000
max_heap_table_size=6400M
myisam_max_sort_file_size=64M
myisam_sort_buffer_size=32M
read_buffer_size=4M
read_rnd_buffer_size=4000M
server_id=1
skip-external-locking=on
sort_buffer_size=256kb
table_open_cache=256
thread_cache_size=16
tmp_table_size=64M
wait_timeout=31536000
interactive_timeout=31536000
sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"
group_concat_max_len=10240
[client]
port=3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
10、再次更改用户文件夹权限
chown -R mysql:mysql /usr/local/mysql
11、初始化数据库
/usr/local/mysql/bin/mysqld --user=mysql --initialize --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
如果报错 提示:
error while loading shared libraries: libaio.so.1: cannot open shared object file directory
可以执行以下命令
yum install libaio-devel.x86_64
12、继续执行初始化数据库命令
/usr/local/mysql/bin/mysqld --user=mysql --initialize --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
13、查看初始化密码 日志文件在 /usr/local/mysql/mysql.log
14、修改配置,挨个执行,如果报错,跳过
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chmod +x /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --list mysqld
15、修改环境变量,并重载环境变量文件
- 打开
/etc/profile
在底部添加如下命令
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib
export PATH
- 执行
source /etc/profile
16、启动mysql
service mysql start
17、登录mysql,密码是上面的初始化密码
mysql -uroot -p;
- 如果不行进到
/etc/my.cnf
里 在[mysqld]
下添加
skip-grant-tables
- 改完密码记得回来去掉
- 第一次登录必须要先修改密码不然会提示:
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
18、执行修改密码命令
flush privileges;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'mysql';
- 注意退出不像MariaDB能ctrl c 退出,下面二选一
exit
quit
19、mysql启动后,连接不上,不显示3306端口
vim /etc/my.cnf
,注释掉下面两行内容,重启mysql就可以
#skip_networking
#skip-grant-tables
netstat -untlp
vim /etc/my.cnf
service mysqld restart
- 这下有3306了
20、授权远程访问
update user set host='%' where user='root'