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

注:出这个版本的安装方式使用因为  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

a8a3fb28ea3daf3616d2731c21c2eec8.png

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

cd /etc/yum.repos.d/

vim mysql-community.repo

a7c45ddfebe19a3bae126d10de911a6e.png

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

yum repolist all | grep mysql

aea4451d705779027c193f02824655fc.png

yum install mysql-server -y

9ae45f9a7080577bdaa0825ab2186e98.png

# 加入开机自启动

systemctl enable mysqld

# 启动mysql服务进程

systemctl start mysqld

# 查看mysql服务进程

systemctl status mysqld

e9bcc5f698ca78b23139c6e825b736d9.png

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

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

814bb205aaaa585d2933a8594e355c8c.png

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

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

fdf00e84e8c1f05cdbecc617e014043b.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;

ps:mysql5.6的 my.cnf配置文件,

# For advice on how to change settings please see

# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

[mysqld]

#

# Remove leading # and set to the amount of RAM for the most important data

# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

# innodb_buffer_pool_size = 128M

#

# Remove leading # to turn on a very important data integrity option: logging

# changes to the binary log between backups.

# log_bin

#

# Remove leading # to set options mainly useful for reporting servers.

# The server defaults are faster for transactions and fast SELECTs.

# Adjust sizes as needed, experiment to find the optimal values.

# join_buffer_size = 128M

# sort_buffer_size = 2M

# read_rnd_buffer_size = 2M

port=33069

lower_case_table_names=1

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

# Recommended in standard MySQL setup

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值