CentOS 安装MySQL 5.7干货来袭~

简介

在CentOS中默认安装有MariaDB,这个是MySQL的分支,但为了需要,还是要在系统中安装MySQL,而且安装完成之后可以直接覆盖掉MariaDB。

  • 下载并安装MySQL官方的 Yum Repository
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

使用上面的命令就直接下载了安装用的Yum Repository,大概25KB的样子,然后就可以直接yum安装了。

yum -y install mysql57-community-release-el7-10.noarch.rpm

之后就开始安装MySQL服务器。

yum -y install mysql-community-server

这步可能会花些时间,安装完成后就会覆盖掉之前的mariadb。

至此MySQL就安装完成了,然后是对MySQL的一些设置。

  • MySQL数据库设置

首先启动MySQL

systemctl start mysqld.service

查看MySQL运行状态,运行状态如图:

systemctl status mysqld.service

此时MySQL已经开始正常运行,不过要想进入MySQL还得先找出此时root用户的密码,通过如下命令可以在日志文件中找出密码:

grep "password" /var/log/mysqld.log

如下命令进入数据库:

mysql -uroot -p

输入初始密码(是上面图片最后面的 no;e!5>>alfg),此时不能做任何事情,因为MySQL默认必须修改密码之后才能操作数据库:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';

其中‘new password’替换成你要设置的密码,注意:密码设置必须要大小写字母数字和特殊符号(,/';:等),不然不能配置成功

如果要修改为root这样的弱密码,需要进行以下配置:

查看密码策略

show variables like '%password%';

修改密码策略

vi /etc/my.cnf

添加validate_password_policy配置

选择0(LOW),1(MEDIUM),2(STRONG)其中一种,选择2需要提供密码字典文件

#添加validate_password_policy配置

validate_password_policy=0

#关闭密码策略

validate_password = off

重启mysql服务使配置生效

systemctl restart mysqld

然后就可以修改为弱密码啦

  • 开启mysql的远程访问

执行以下命令开启远程访问限制(注意:下面命令开启的IP是 192.168.0.1,如要开启所有的,用%代替IP):

grant all privileges on *.* to 'root'@'192.168.0.1' identified by 'password' with grant option;

然后再输入下面两行命令


flush privileges;
exit;
  • 为firewalld添加开放端口

添加mysql端口3306

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

然后再重新载入

firewall-cmd --reload
  • 修改mysql的字符编码(不修改会产生中文乱码问题)

显示原来编码:

show variables like '%character%';

修改/etc/my.cnf


[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'

重启数据库

点赞
  1. sinequan tablets说道:
    Google Chrome Windows 10

    I simply needed to thank you so much once again. I am not sure the things that I would've implemented without the type of recommendations provided by you on such a question. It previously was a very frightful dilemma in my opinion, however , noticing the very specialised mode you processed that made me to leap over gladness. I am just happy for this information and in addition hope that you know what a great job you are always getting into teaching people thru your web blog. More than likely you have never got to know any of us.

  2. venlor online说道:
    Google Chrome Windows 10

    A lot of thanks for all your efforts on this site. Gloria loves engaging in investigation and it's easy to understand why. Almost all know all concerning the dynamic means you give important secrets on the web blog and as well encourage contribution from others on that concern plus our daughter is always discovering a lot. Have fun with the remaining portion of the new year. You're the one conducting a good job.

  3. quetiapine pills说道:
    Google Chrome Windows 10

    I happen to be writing to make you understand what a useful experience our princess went through visiting yuor web blog. She realized too many things, with the inclusion of what it is like to possess an incredible teaching style to make the others without hassle thoroughly grasp various very confusing topics. You undoubtedly surpassed visitors' expected results. Thanks for showing those warm and friendly, trustworthy, revealing not to mention unique tips on your topic to Tanya.

  4. buy wellbutrin说道:
    Google Chrome Windows 10

    I'm just commenting to let you be aware of of the exceptional discovery my cousin's child enjoyed going through your blog. She discovered a wide variety of details, most notably how it is like to have a very effective coaching heart to get many more effortlessly fully understand certain extremely tough matters. You actually did more than my desires. I appreciate you for displaying such helpful, healthy, educational and also cool guidance on that topic to Evelyn.

  5. risnia buy说道:
    Google Chrome Windows 10

    A lot of thanks for all your efforts on this site. Gloria enjoys engaging in investigation and it's easy to understand why. Almost all know all concerning the dynamic means you deliver great items on the web blog and as well encourage contribution from other people on that concern plus our daughter is actually being taught a lot. Have fun with the remaining portion of the new year. You're the one conducting a glorious job.

  6. Google Chrome Windows 10

    Thanks for your whole work on this website. My mum takes pleasure in setting aside time for research and it is simple to grasp why. We notice all relating to the powerful ways you render very useful tips and tricks via your website and therefore strongly encourage response from website visitors on this theme while our own simple princess is without a doubt understanding so much. Take pleasure in the rest of the year. Your performing a very good job.

  7. Google Chrome Windows 10

    I'm commenting to let you be aware of of the beneficial discovery my child encountered browsing the blog. She came to understand a lot of details, including how it is like to have a great coaching character to get certain people completely comprehend a variety of complex issues. You actually did more than her desires. I appreciate you for coming up with such essential, dependable, edifying and cool guidance on that topic to Ethel.

  8. cheap amoxapine说道:
    Google Chrome Windows 10

    I am glad for writing to make you know what a notable encounter my wife's girl had studying your web site. She mastered several pieces, which include what it's like to possess an awesome helping nature to let other individuals with ease know precisely some problematic subject matter. You truly exceeded people's expectations. Thank you for producing these practical, trusted, informative and in addition fun tips about this topic to Kate.

  9. Google Chrome Windows 10

    I'm commenting to let you be aware of of the awesome discovery my child developed browsing the blog. She came to find a good number of details, including how it is like to have a great coaching character to get a number of people clearly completely grasp a number of advanced issues. You actually did more than her desires. I appreciate you for churning out such beneficial, dependable, edifying and cool guidance on that topic to Emily.

  10. vardenafil pills说道:
    Google Chrome Windows 10

    A lot of thanks for each of your hard work on this web page. Kim really likes going through investigation and it's really easy to understand why. Many of us know all of the dynamic method you make powerful strategies on this web blog and as well as improve participation from people on that issue so our girl is in fact learning a lot of things. Have fun with the remaining portion of the new year. You are conducting a pretty cool job.

  11. vardenafil说道:
    Google Chrome Windows 10

    A lot of thanks for all your efforts on this site. Gloria loves engaging in investigation and it's easy to understand why. Almost all know all concerning the dynamic means you deliver helpful items on the web blog and as well encourage contribution from other people on that concern plus our daughter is actually discovering a lot. Have fun with the remaining portion of the new year. You're the one conducting a good job.

  12. Google Chrome Windows 10

    Bardzo lubię patrzeć i uważam, że ta strona zawiera naprawdę przydatna strona!

  13. 席小欢说道:
    Google Chrome Windows 10

    向你申请交换首页友情链接,同意的话请回复一下

    生活常识网

    http://wozhidaole.com.cn/

    网友们想与我站互相友情链接的,可以去我站申请!

发表评论

电子邮件地址不会被公开。必填项已用 * 标注