欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

centOS安装mysql5.7详细教程

程序员文章站 2022-06-24 13:36:03
本文为大家分享了centos下安装mysql5.7详细步骤,供大家参考,具体内容如下 第一步: 第一句检测系统是否自带安装mysql,若有执行第二句删除系统自带的...

本文为大家分享了centos下安装mysql5.7详细步骤,供大家参考,具体内容如下

第一步:

第一句检测系统是否自带安装mysql,若有执行第二句删除系统自带的mysql及其依赖。

yum list installed | grep mysql
yum -y remove mysql-libs.x86_64

第二步:

给centos添加rpm源,并且选择较新的源,下面代码逐句执行

wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
yum localinstall mysql-community-release-el6-5.noarch.rpm
yum repolist all | grep mysql
yum-config-manager --disable mysql55-community
yum-config-manager --disable mysql56-community
yum-config-manager --enable mysql57-community-dmr
yum repolist enabled | grep mysql

第三步:

安装mysql 服务器

yum install mysql-community-server

第四步:

service mysqld start

第五步:

查看mysql是否自启动,并且设置开启自启动

chkconfig --list | grep mysqld
chkconfig mysqld on

第六步:

这一步很重要!!!

不知道从mysql哪个版本开始,mysql的root默认密码就不为空了,在安装的过程中默认密码保存在安装日志中了。我们要通过安装日志找到默认密码,用默认密码登陆mysql成功后会强行让你修改密码,修改的密码还要够复杂(复合mysql默认的密码策略)才能修改成功,一般带大小写字母特殊字符和数字超过8个字符就可以。

首先找到安装日志

find / -name mysqld.log

然后发现该日志文件路径在 /var/log/mysqld.log。然后用下面命令打开,按‘i'键上翻

vim /var/log/mysqld.log

centOS安装mysql5.7详细教程

上图红色地方就是root密码所在地

第七步:

mysql安全设置

mysql_secure_installation

输入上面命令进行下面步骤

servers in production use! please read each step carefully!
in order to log into mysql to secure it, we'll need the current
password for the root user. if you've just installed mysql, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
enter current password for root (enter for none):<–初次运行,输入刚刚找到的初始密码,会强制你先修改密码才能进行下去
ok, successfully used password, moving on…
setting the root password ensures that nobody can log into the mysql
root user without the proper authorisation.
set root password? [y/n] <– 是否设置root用户密码,输入y并回车或直接回车
new password: <– 设置root用户的密码
re-enter new password: <– 再输入一次你设置的密码
password updated successfully!
reloading privilege tables..
… success!
by default, a mysql installation has an anonymous user, allowing anyone
to log into mysql without having to have a user account created for
them. this is intended only for testing, and to make the installation
go a bit smoother. you should remove them before moving into a
production environment.
remove anonymous users? [y/n] <– 是否删除匿名用户,生产环境建议删除,所以直接回车
… success!
normally, root should only be allowed to connect from 'localhost'. this
ensures that someone cannot guess at the root password from the network.
disallow root login remotely? [y/n] <–是否禁止root远程登录,根据自己的需求选择y/n并回车,建议禁止
… success!
by default, mysql comes with a database named 'test' that anyone can
access. this is also intended only for testing, and should be removed
before moving into a production environment.
remove test database and access to it? [y/n] <– 是否删除test数据库,直接回车
- dropping test database…
… success!
- removing privileges on test database…
… success!
reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
reload privilege tables now? [y/n] <– 是否重新加载权限表,直接回车
… success!
cleaning up…
all done! if you've completed all of the above steps, your mysql
installation should now be secure.
thanks for using mysql!
[root@server1 ~]#

第八步:

可选步骤,原来linux下的mysql默认是区分表名大小写的,通过如下设置,可以让mysql不区分表名大小写:
1、用root登录,修改 /etc/my.cnf;
2、在[mysqld]节点下,加入一行: lower_case_table_names=1
3、重启mysql即可; service mysqld restart

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。