Centos 6.8 安装Mysql 5.6 ,在线安装

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

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

二、安装配置

首先下载mysql数据库并配置

wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
rpm -ivh mysql-community-release-el6-5.noarch.rpm
yum repolist all | grep mysql

然后安装

yum install mysql-community-server -y

三、设置开机启动

2、3、4都是on代表开机自动启动

chkconfig --list | grep mysqld
chkconfig mysqld on

四、设置远程root

启动mysql服务

service mysqld start

安装完mysql-server后会提示执行" 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编码

登录root用户,查看mysql原本编码

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

mysql> show variables like 'character%';

编辑mysql的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

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

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

mysql> show variables like 'character%';

六、对外开放远程

首先,编辑" vi /etc/sysconfig/iptables “文件
在这里插入图片描述
然后按” i “键,插入防火墙策略,按ESC退出后” :wq "保存

-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT

在这里插入图片描述
最后重启" service iptables restart "
在这里插入图片描述

七、带小写敏感设置

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

八、启动关闭

启动:# service mysqld start
关闭:# service mysqld stop

查看版本:mysql -V

查看进程:ps -ef | grep mysqld
如果有mysqld_safe和mysqld两个进程,说明MySQL服务当前在启动状态;

在这里插入图片描述

九、参考网址

https://www.cnblogs.com/007sx/p/7083143.html
https://my.oschina.net/sdlvzg/blog/1560822
https://www.cnblogs.com/jimboi/p/6405560.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值