MySQL5.7安装教程(RPM)

前言:

对应服务器信息:

192.168.247.53


一、MySQL安装(RPM

1.系统环境设置:

1.1清空系统mysql

安装mysql之前需要将系统自带的mysql包进行删除: 

yum remove all mysql\*

1.2SELinux设置

vim /etc/selinux/config 
输入:
disabled

reboot
getenforce 
df -lh (确保拥有4G空间可用)

1.3安装依赖包

yum install libaio\*  -y
yum install apt-get\* -y
yum -y install numactl -y

2.  安装rpm包(5.7.27

2.1安装server

rpm -ivh mysql-community-server-5.7.27-1.el6.x86_64.rpm --force --nodeps

2.2安装client

扫描二维码关注公众号,回复: 8663664 查看本文章
rpm -ivh mysql-community-client-5.7.27-1.el6.x86_64.rpm --force --nodeps

3.设置防火墙

firewall-cmd --permanent --add-port=3306/tcp
firewall-cmd --reload 

4.  启动服务

chmod +x /etc/rc.local 
vim /etc/rc.local 
输入:
service mysqld start
service mysqld start

4.1MySQL5.7_linux7_bug

重启系统后会发报错,异常信息如下:
[root@mysql_master ~]# ls /var/run/mysqld/
ls: cannot access /var/run/mysqld/: No such file or directory

之所以/var/run/mysqld 目录每次重启后都需要手动去创建,是因为/var/run/目录下建立文件夹是在内存中,故每次重启后内存被清空导致/var/run/mysqld 也被清除,从而导致无法启动mysql。这也就是MySQL5.7的一个bug(在Linux6里面安装没有这个异常)

解决方法一:
设置开机启动自动创建该目录:
chmod +x /etc/rc.local 
vim /etc/rc.local 
在尾部添加:
mkdir -p /var/run/mysqld/

4.2设置开机启动

[root@mysql_master ~]# chkconfig --add mysqld
[root@mysql_master ~]# chkconfig mysqld on
[root@mysql_master ~]# reboot
[root@mysql_master ~]# netstat -ntulp | grep 3306

 5.设置密码

关闭密码复杂度:vim /etc/my.cnf   在最后添加:validate-password=OFF

5.1方法一:

grep 'temporary password' /var/log/mysqld.log
显示:
2019-12-19T05:59:07.456434Z 1 [Note] A temporary password is generated for root@localhost: YhcnyQCco4>g
[root@mysql_master ~]# mysql -uroot -p
Enter password: (YhcnyQCco4>g)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';  (CentOS6.8)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Tansk01@'; (CentOS7x默认启用复合密码复杂度,关闭密码复杂度:vim /etc/my.cnf   在最后添加:validate-password=OFF)
mysql> flush privileges;

5.2方法二:

mysql_secure_installation 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y
New password: (123456)
Re-enter new password: (123456)

登录验证:mysql -uroot -p123456

5.3方法三: 

mysqladmin -uroot -p123456(old_passwd) password 654321(new_passwd)
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

5.4方法四:

[root@MySQL33 ~]# service mysqld stop                       
[root@MySQL33 ~]# /usr/bin/mysqld_safe --skip-grant-tables &
 有的时候自定义的目录,需要用自定义的目录:
[root@MySQL33 ~]# /var/lib/mysql5.7/mysql5.7.28/bin/mysqld_safe  --skip-grant-tables &

无密码登录:
[root@MySQL33 ~]# mysql -uroot -p
Enter password:  (enter)
mysql5.7以后:mysql.user表中没有了password字段,而是使用authentication_string来代替。
5.4.1mysql5.7之前:
mysql> update mysql.user set password=password("123456") where user="root";
5.4.2mysql5.7之后:
mysql> update mysql.user set authentication_string=password('123456') where User='tansk';  

5.5方法五:

(用户登录后修改自己的密码)
mysql> set password=password('123456');

6.  创建用户与数据库

mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.27   |
+-----------+
mysql> create database tanskdb;
mysql> grant all on tanskdb.* to tansk@localhost identified by '123456'; 
mysql> flush privileges;

7.  授权访问 

7.1指定IP

mysql> grant all privileges on *.* to 'root'@'192.168.43.87' identified by '123456'; 

7.2所有IP

mysql> grant all privileges on *.* to 'root'@'%' identified by '123456';
如果想要这个“root”用户可用用过workbench创建用户,仍需赋予以下权限:
mysql> grant GRANT OPTION on *.* to 'root'@'%' identified by '123456';  

7.3回收权限:

mysql> revoke insert on *.* from 'root'@'localhost';

7.4测试连接:

连接工具:workbench8.0


原创帖,转载需注明出处 

 

 

 

 

 

猜你喜欢

转载自www.cnblogs.com/tanshouke/p/12205560.html