Centos 7服务器搭建(二)—安装MySQL

在Centos6.*下,安装mysql可以直接用yum实现:

yum install mysql mysql-server mysql-libs mysql-server

但在Centos 7下,安装mysql-server会失败,因为甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此开源社区采用分支的方式来避开这个风险,维护MySQL的分支MariaDB,同样采用GPL授权许可。MariaDB 团队正尽力保持对 MySQL 的全面兼容,因此完全可以从mysql迁移到MariaDB,甚至不用改任何东西,只是把安装的数据库软件换掉。
(1)安装
依然用yum来安装

yum install mariadb-server mariadb 

(2)启动

systemctl start mariadb

其它响应命令是:

systemctl start mariadb #启动MariaDB

systemctl stop mariadb #停止MariaDB

systemctl restart mariadb #重启MariaDB

systemctl enable mariadb #设置开机启动

(3)使用
使用方法和MySQL一样,甚至可以直接用MySQL的命令

[root@****]mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
………………………………

(4)配置密码
进入MySQL后,

mysql> set password for 'root'@'localhost' =password('password');
Query OK, 0 rows affected (0.00 sec)

mysql>

直接生效,不需要重启数据库。

(5)其它配置

  • 编码
    mysql配置文件为/etc/my.cnf,只需要在其中加上编码配置即可
[mysql]
default-character-set =utf8

需要注意的是这里的编码需要和/usr/share/mysql/charsets/Index.xml中的一样

  • 远程连接
    赋予root用户所有权限
mysql> grant all privileges on *.* to root@'%'identified by 'password';

mysql> grant all privileges on *.* to root@localhost identified by 'password';

mysql> grant all privileges on *.* to root@192.169.1.* identified by 'password';

如果是新用户而不是root,则要先新建用户,

mysql>create user 'username'@'%' identified by 'password';

之后记得要刷新权限:

flush privileges;

(6)开放firewalld端口
如果需要加入远程访问,需要开放对应的端口,默认是3306

firewall-cmd --list-all(查看规则)
firewall-cmd --add-port=3306/tcp --permanent
firewall-cmd --reload
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值