Centos7安装mysql

1.快速删除
yum remove  mysql mysql-server mysql-libs mysql-server


2.查找残留文件
rpm -qa | grep -i mysql

3.将查询出来的文件逐个删除,如:

yum remove mysql-community-common-5.7.20-1.el6.x86_64


4.查找残留目录
whereis mysql


逐条删除目录,如:

rm –rf /usr/lib64/mysql

上述做完后,
最好重新查询相关内容,防止漏删

检测系统是否存在mysql

yum list installed | grep mysql

删除mysql依赖项

yum -y remove mysql-libs.x86_64


centos7安装mysql5.7
# 下载mysql源安装包
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
# 安装mysql源
yum localinstall mysql57-community-release-el7-8.noarch.rpm
检查mysql源是否安装成功
yum repolist enabled | grep "mysql.*-community.*"
有如下则成功
mysql-connectors-community/x86_64       MySQL Connectors Community            74
mysql-tools-community/x86_64            MySQL Tools Community                 74
mysql57-community/x86_64                MySQL 5.7 Community Server           307

安装mysql
yum install mysql-community-server

报错:Error: Package: mysql-community-server-5.7.20-1.el7.x86_64 (mysql57-community)
           Requires: libsasl2.so.3()(64bit)
Error: Package: mysql-community-client-5.7.20-1.el7.x86_64 (mysql57-community)
           Requires: libstdc++.so.6(GLIBCXX_3.4.15)(64bit)
Error: Package: mysql-community-libs-5.7.20-1.el7.x86_64 (mysql57-community)
           Requires: libc.so.6(GLIBC_2.14)(64bit)
看提示需要libsasl2.so.3()(64bit)-----libstdc++.so.6(GLIBCXX_3.4.15)(64bit)-------------libc.so.6(GLIBC_2.14)(64bit)

解决:yum install libstdc++ 
yum install libc.so 

修改vim /etc/yum.repos.d/mysql-community.repo 源文件为

[mysql57-community]


name=MySQL 5.7 Community Server


## baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/ ??


baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/


enabled=1


gpgcheck=0


gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql? 

yum install mysql-community-server  #再次安装mysql

启动MySQL服务
systemctl start mysqld
查看MySQL的启动状态
systemctl status mysqld
准备重置密码,先查看随机密码:
grep 'temporary password' /var/log/mysqld.log   
登陆:
mysql -u root -p
进去后改密码: 
alter user 'root'@'localhost' identified by 'zjx';  

登陆报错:
在[mysqld]后面任意一行添加“skip-grant-tables”用来跳过密码验证
然后进去改密码,改完删了这句重新启动就ok

改密码报错:可能原因:更改密码必须满足:数字、小写字母、大写字母 、特殊字符、长度至少8位
在 vim /etc/my.cnf配置文件中增加 validate_password=off   并重启mysqld -------service mysqld restart

刷新权限;
 flush privileges;
添加新用户     
CREATE USER ‘root‘@‘%‘ IDENTIFIED BY ‘密码‘;
修改密码:
update mysql.user set authentication_string=password('root') where user='root' ;
flush privileges;
开机自启:
systemctl enable mysqld
systemctl daemon-reload

以下非必需:
默认只允许root帐户在本地登录,如果要在其它机器上连接mysql,必须修改root允许远程连接,或者添加一个允许远程连接的帐户,为了安全起见,我添加一个新的帐户:

mysql> GRANT ALL PRIVILEGES ON *.* TO 'zjx'@'%' IDENTIFIED BY 'zjx103!' WITH GRANT OPTION;
7、配置默认编码为utf8
修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:

[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
重新启动mysql服务


安装完不能用navicat连接:解决:
mysql> use mysql;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> update user set host = '%' where user = 'root';
ERROR 1046 (3D000): No database selected
mysql> FLUSH PRIVILEGES;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> SET PASSWORD = PASSWORD('103zjx');
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> set global validate_password_length=6;
Query OK, 0 rows affected (0.00 sec)

mysql> SET PASSWORD = PASSWORD('103zjx');
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_mixed_case_count=0;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_number_count=3;
Query OK, 0 rows affected (0.00 sec)

mysql>  set global validate_password_special_char_count=0;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_length=3;
Query OK, 0 rows affected (0.00 sec)

mysql> SHOW VARIABLES LIKE 'validate_password%';
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> set global validate_password_number_count=3;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_number_count=3;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_number_count=3;
Query OK, 0 rows affected (0.00 sec)

mysql> SET PASSWORD = PASSWORD('103');
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.02 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值