centos yum mysql 5.6_centos7 yum方式安装 mysql5.6版本数据库

本文介绍了在CentOS 7系统中,如何通过yum命令安装MySQL 5.6版本,包括卸载原有MariaDB、下载安装源、设置密码、初始化数据库以及配置远程连接。
摘要由CSDN通过智能技术生成

edf785913ea463b60ad5cee71bf53317.png

注:出这个版本的安装方式使用因为  centos自带mariadb

其实yum方式安装是可以不用删除mariadb的,安装MySQL会覆盖掉之前已存在的mariadb

1:下载源文件

wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm

2:判断当前centos系统中是否有已存在的mysql,有则卸载即可

yum list installed | grep mysql

#删除系统自带的mysql

yum -y remove mysql-libs.x86_64

#卸载后再用全局查找,查找出残留的文件等信息,继续删除

find / -name mysql

#rm -rf 自行删除查询出来的目录,若没有则无需删除

由于这个mysql的yum源服务器在国外,所以下载速度会比较慢,mysql5.6只有79M大,而mysql5.7就有182M。(其实就是你服务器垃圾,没别的)

3:安装mysql-community-release-el7-5.noarch.rpm包

rpm -ivh mysql57-community-release-el7-7.noarch.rpm

安装完这个包后,会获得两个mysql的yum repo源:/etc/yum.repos.d/mysql-community.repo,/etc/yum.repos.d/mysql-community-source.repo

24e2bfbb9ed2184c8af095f67a3d9b5d.png

#进入/etc/yum.repos.d/

cd /etc/yum.repos.d/

vim mysql-community.repo

eb671843f617bdbbb2d57ca6e0e141ff.png

用yum repolist mysql这个命令查看一下是否已经有mysql可安装文件

yum repolist all | grep mysql

b690e4a56d1c52ef805a3e5ed06730fb.png

yum install mysql-server -y

6793f8de1b01fda93872ddd39bde6fba.png

# 加入开机自启动

systemctl enable mysqld

# 启动mysql服务进程

systemctl start mysqld

# 查看mysql服务进程

systemctl status mysqld

a8cb085eaab3ffdaa1143268ca870179.png

4:安装完毕后 mysql会生成一个随机密码 命令查看:

cat /var/log/mysqld.log |grep password

e0c52739d0dc6d84f4ed7db59fb0e4e5.png

5:查看是否可以用密码登录:

mysql -uroot -p?j/6P-ou#D<1

0d28f1a74ed569c9c798dfbbd1bc6c30.png

6:初始化数据库(请注意如下设置)

mysql_secure_installation

[root@localhost ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL

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] y #是否设置root密码

New password:

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] y #是否删除匿名用户

... 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] n #是否禁止root用户远程登录

... skipping.

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] y #是否删除test数据库

- Dropping test database...

ERROR 1008 (HY000) at line 1: Can"t drop database "test"; database doesn"t exist

... Failed! Not critical, keep moving...

- 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] y #是否刷新权限配置生效

... Success!

All done! If you"ve completed all of the above steps, your MySQL

installation should now be secure.

Thanks for using MySQL!

Cleaning up...

6:远程连接mysql、Navicat等工具连接的时候、就是远程连接、而不是登陆的账号密码了。

若远程连接账号密码都是对的、但是连接不上、可能就是防火墙没有添加3306端口、添加上就OK了

配置:

登陆mysql

mysql>use mysql;

mysql>GRANT ALL PRIVILEGES ON *.* TO "myuser"@"%" IDENTIFIED BY "mypassword" WITH GRANT OPTION;

mysql> flush privileges;

mysql> exit;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值