Centos 7 安装Mysql 5.6 ,在线安装

一、检查系统是否安装其他版本Mariadb数据库

注意:在新版本的CentOS7中,默认的数据库已更新为了Mariadb,而非 MySQL。

# 查看已安装的 Mariadb 数据库版本
rpm -qa|grep -i mariadb
# 卸载已安装的 Mariadb 数据库
rpm -qa|grep mariadb|xargs rpm -e --nodeps
# 再次查看已安装的 Mariadb 数据库版本,确认是否卸载完成
rpm -qa|grep -i mariadb

二、下载mysql安装包,并安装

# 2.1下载安装包文件
wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
或者
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

# 2.2安装mysql-community-release-el6-5.noarch.rpm包
rpm -ivh mysql-community-release-el6-5.noarch.rpm

# 2.3执行yum命令查看可用的 mysql 安装文件
yum repolist all | grep mysql

# 2.4安装mysql
yum install mysql-community-server -y

# 2.5检查mysql是否安装成功
rpm -qa | grep mysql

三、安装完成后,初次安装执行安全配置向导

3.1加入开机启动

#第一种方式,如果报错使用第二种
systemctl enable mysqld

#第二种方式
# 2、3、4都是on代表开机自动启动
/sbin/chkconfig mysqld on
chkconfig --list | grep mysqld

3.2启动mysql服务

# 启动
systemctl start mysqld
# 查看服务是否启动成功
systemctl status mysqld

3.3配置root信息
安装完成后执行【mysql_secure_installation】,设置内容如下:

  1. 为root用户设置密码
  2. 删除匿名账号
  3. 取消root用户远程登录
  4. 删除test库和对test库的访问权限
  5. 刷新授权表使修改生效
[root@centosServer ~]# 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用户密码,输入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] 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] n			##<– 是否删除test数据库,直接回车
 ... skipping.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] 							##<– 是否重新加载权限表,直接回车
 ... 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...

四、远程连接

# 登录root用户建立远程连接
[root@centosServer ~]# mysql -uroot -p

# 授权命令
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你设置的密码' WITH GRANT OPTION;
mysql> flush privileges;

五、设置UTF-8编码

5.1登录root用户,查看mysql默认编码

[root@centosServer ~]# mysql -uroot -p

mysql> show variables like 'character%';

5.2编辑mysql的my.cnf文件,设置UTF-8编码

# 编辑my.cnf文件
[root@centosServer ~]# vi /etc/my.cnf

#设置编码内容
[mysqld]
character-set-server=utf8 
collation-server=utf8_general_ci 
performance_schema_max_table_instances=400 
table_definition_cache=400 
table_open_cache=256
lower_case_table_names=1
# 修改
# sql_mode='NO_ENGINE_SUBSTITUTION'
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

[mysql]
default-character-set = utf8

[mysql.server]
default-character-set = utf8

[mysqld_safe]
default-character-set = utf8

[client]
default-character-set = utf8

5.3重启mysql服务,查看验证编码

[root@centosServer ~]# systemctl restart mysqld
[root@centosServer ~]# mysql -uroot -p

mysql> show variables like 'character%';

六、开启远程访问

# 查询3306端口是否开放
firewall-cmd --query-port=3306/tcp
# 开放3306端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
# 重启
firewall-cmd --reload
# 查看防火墙是否放行3306端口
firewall-cmd --zone=public --list-ports

七、大小写敏感设置

# 编辑my.cnf文件
vi  /etc/my.cnf
# 插入
lower_case_table_names=1

八、常用命令

启动:# systemctl start mysqld.service
关闭:# systemctl stop mysqld.service
重启:# systemctl restart mysqld.service
自启动:# systemctl enable mysqld.service

查看版本:mysql -V

查看进程:ps -ef | grep mysqld
如果有mysqld_safe和mysqld两个进程,说明MySQL服务当前在启动状态;
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值