mysql安装包安装步骤(mysql安装教程详细教程)

部署mysql5.7.25

1、下载rpm安装包。
2、上传到服务器,解压。
3、卸载之前的版本。
4、按照顺序安装:

Rw.HAo22。Com

rpm -ivh mysql-community-common-5.7.25-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.25-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-5.7.25-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.25-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.25-1.el7.x86_64.rpm

5、修改配置文件为无需密码登陆

vi /etc/my.cnf

[mysqld]#下添加
skip-grant-tables=1 #不用验证,无需密码登陆

6、修改默认字符集为utf8

vi /etc/my.cnf

[mysqld]#下添加
character-set-server=utf8
collation-server=utf8_general_ci
[mysql]#下添加
default-character-set=utf8

7、启动mysql

systemctl start mysqld;

8、查看启动是否报错

systemctl status mysqld

9、【知识点】登陆mysql,默认已创建如下四个库。同时my.cnf中配置的datadir指定目录下存在如下四个库的文件夹。

centos部署mysql-全方位解析数据库安装


10、修改密码

mysql>use mysql
mysql>update user set
mysql>authentication_string=password("123456’) ,
mysql>password_expired="N’,password_last_changed=now()
mysql>where user="root’;
mysql>flush privileges;
mysql> alter user "root’@"localhost’ identified by "123456’;
mysql>Flush privileges;
mysql>exit;
同时my.cnf 删除参数skip-grant-tables=1,
重启mysql:systemctl restart mysqld 。

11、测试是否可用

mysql -uroot -p -e “show databases;”;–安全起见-p不加密码

12、配置可被其他主机访问
新增host为"%’的用户:

create user readonly@% identified by’readonly’;
grant select on . toreadonly@%;

13、确认网络连通的前提,开放防火墙端口

Rw.HAo22。Com

firewall-cmd –zone=public –add-port=3306/tcp –permanent

14、重新启动防火墙

firewall-cmd –reload

卸载mysql5.7.25

1、卸载程序:由于存在依赖关系,故需要按如下顺序卸载

rpm -e mysql-community-server-5.7.25-1.el7.x86_64
rpm -e mysql-community-devel-5.7.25-1.el7.x86_64
rpm -e mysql-community-client-5.7.25-1.el7.x86_64
rpm -e mysql-community-libs-5.7.25-1.el7.x86_64

2、清除余项

Rw.HAo22。Com

whereis mysql
rm -rf 相关文件

3、删除配置文件

rm -rf /etc/my.cnf*

4、删除默认datadir路径

rm –rf /var/lib/mysql

5、剩余配置检查:(此次操作如下无结果)

chkconfig –list | grep -i mysql
chkconfig –del mysql

问题鉴赏

Rw.HAo22。Com

1、关闭selinux
报错:

2019-03-12T17:28:58.770891Z 0 [ERROR] InnoDB: Operating system error number 13 in a file operation.
2019-03-12T17:28:58.770912Z 0 [ERROR] InnoDB: The error means mysqld does not have the access rights to the directory.
2019-03-12T17:28:58.770918Z 0 [ERROR] InnoDB: os_file_get_status() failed on "./ibdata1". Can"t determine file permissions
2019-03-12T17:28:58.770928Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2019-03-12T17:28:59.371503Z 0 [ERROR] Plugin "InnoDB" init function returned error.
2019-03-12T17:28:59.371548Z 0 [ERROR] Plugin "InnoDB" registration as a STORAGE ENGINE failed.
2019-03-12T17:28:59.371556Z 0 [ERROR] Failed to initialize builtin plugins.
2019-03-12T17:28:59.371560Z 0 [ERROR] Aborting

解决方法:
查看selinux状态:getenforce。
关闭selinux:setenforce 0。
2、修改密码后show databases报错

mysql>Update mysql.user set authentication_string=password("* * *’) where user=’root’;
mysql>Flush privileges;

此时访问均正常。
退出mysql,配置文件my.cnf 删除参数skip-grant-tables=1,重启mysql可使用密码重新登陆。
登陆后执行指令:

show databases;

报错ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executin。
解决方法:

mysql>alter user "root’@"localhost’ identified by "****’;
mysql>Flush privileges;
mysql>show databases;

3、sql_mode参数赏析

my.cnf新增配置信息sql_mode=;重启mysql。
ONLY_FULL_GROUP_BY:出现在select语句、HAVING条件和ORDER BY语句中的列,必须是GROUP BY的列或者依赖于GROUP BY列的函数列。
NO_AUTO_VALUE_ON_ZERO:该值影响自增长列的插入。默认设置下,插入0或NULL代表生成下一个自增长值。如果用户希望插入的值为0,而该列又是自增长的,那么这个选项就有用了。
STRICT_TRANS_TABLES:在该模式下,如果一个值不能插入到一个事务表中,则中断当前的操作,对非事务表不做限制
NO_ZERO_IN_DATE:这个模式影响了是否允许日期中的月份和日包含0。如果开启此模式,2016-01-00是不允许的,但是0000-02-01是允许的。它实际的行为受到 strict mode是否开启的影响1。
NO_ZERO_DATE:设置该值,mysql数据库不允许插入零日期。它实际的行为受到 strictmode是否开启的影响2。
ERROR_FOR_DIVISION_BY_ZERO:在INSERT或UPDATE过程中,如果数据被零除,则产生错误而非警告。如果未给出该模式,那么数据被零除时MySQL返回NULL
NO_AUTO_CREATE_USER:禁止GRANT创建密码为空的用户
NO_ENGINE_SUBSTITUTION:如果需要的存储引擎被禁用或未编译,那么抛出错误。不设置此值时,用默认的存储引擎替代,并抛出一个异常
PIPES_AS_CONCAT:将”||”视为字符串的连接操作符而非或运算符,这和Oracle数据库是一样的,也和字符串的拼接函数Concat相类似
ANSI_QUOTES:启用ANSI_QUOTES后,不能用双引号来引用字符串,因为它被解释为识别符。

Rw.HAo22。Com