安装前先删除残留:
[root@izwz9hy3mj62nle7573jv5z ~]# rpm -qa | grep -i mysql
[root@izwz9hy3mj62nle7573jv5z ~]#
[root@izwz9hy3mj62nle7573jv5z ~]# find / -name mysql
/root/.jenkins/local_lib/mysql
/etc/selinux/targeted/active/modules/100/mysql
/usr/lib64/mysql
/usr/share/mysql
/usr/bin/mysql
[root@izwz9hy3mj62nle7573jv5z ~]#
安装:
下载地址:https://downloads.mysql.com/archives/community/
# 下载
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-server-5.7.23-1.el7.x86_64.rpm
# 会通过rpm自动下载并且覆盖强制安装
rpm -ivh mysql-community-server-5.7.23-1.el7.x86_64.rpm --force --nodeps
卸载--rpm安装方式的卸载:
# 卸载
rpm -e xxxxxXXX.rpm
卸载--yum安装方式的卸载:
yum remove mariadb*
yum remove mysql*
访问数据库:
mysql -uroot -p
创建用户和授权:
-- 使用命令登录:mysql -u root -p
-- 创建用户 用户名:long 密码:Long@123456
create user 'long'@'%' identified by 'Long@123456';
-- 授权 *.*表示所有库
grant SELECT, REPLICATION SLAVE, REPLICATION CLIENT on *.* to 'long'@'%' identified by 'Long@123456';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
忘记密码:
# 配置跳过授权
[root@izwz9hy3mj62nle7573jv5z ~]# vim /etc/my.cnf
# 如果忘记密码,配置skip-grant-tables,实现访问后跳过授权
[mysqld]
skip-grant-tables
# 重启mysql,再次登陆无需
重设密码:
flush privileges;
set password for root@localhost = password('123456');
flush privileges;
重设密码后注释掉skip-grant-talbes
创建用户和授权:
-- 使用命令登录:mysql -u root -p
-- 创建用户 用户名:canal 密码:Canal@123456
create user 'canal'@'%' identified by 'Canal@123456';
-- 授权 *.*表示所有库
grant SELECT, REPLICATION SLAVE, REPLICATION CLIENT on *.* to 'canal'@'%' identified by 'Canal@123456';
重启:
service mysqld restart