centos 7 安装mariadb

卸载mysql

# rpm -qa|grep mysql
mysql-community-common-5.6.30-2.el7.x86_64
mysql-community-libs-5.6.30-2.el7.x86_64
# yum remove mysql-community-libs mysql-community-common

  

 mkdir /var/log/mariadb/

mkdir /var/run/mariadb/

1、在 /etc/yum.repos.d/ 下建立 MariaDB.repo,内容如下: 
[azureuser@mono etc]$ cd /etc/yum.repos.d 
[azureuser@mono yum.repos.d]$ vi MariaDB.repo

# MariaDB 10.0 CentOS repository list - created 2013-08-23 13:08 UTC 
http://mariadb.org/mariadb/repositories/ 
[mariadb] 
name = MariaDB 
baseurl = http://yum.mariadb.org/10.0/centos6-amd64 
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB 
gpgcheck=1

如果是其他的操作系统,可以在这里找到相关信息。

2、使用YUM安装MariaDB 
[azureuser@mono yum.repos.d]$ sudo yum -y install MariaDB-client MariaDB-server MariaDB-devel

vi /etc/my.cnf

不要使用中文,用默认的latin1,不然hive会出各种奇怪报错

[mysqld] 
init_connect='SET collation_connection = utf8_unicode_ci' 
init_connect='SET NAMES utf8' 
character-set-server=utf8 
collation-server=utf8_unicode_ci 
skip-character-set-client-handshake

[client]
default-character-set=utf8

[mysql]
default-character-set=utf8

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

  

3、启动数据库 
[azureuser@mono yum.repos.d]$ sudo service mysql start 

启动报错则执行:mysql_install_db --user=mysql --ldata=/var/lib/mysql/ 

4、修改Root的密码

[azureuser@mono yum.repos.d]$ mysqladmin -u root password ‘passwd’

5、配置远程访问,MariaDB为了安全起见,默认情况下绑定ip( 127.0.0.1)。

[azureuser@mono yum.repos.d]$ mysql -u root -p 
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or g. 
Your MariaDB connection id is 4 
Server version: 10.0.4-MariaDB MariaDB Server

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY ‘passwd’ WITH GRANT OPTION;

MariaDB [(none)]> flush privileges;

第一句中"%"表示任何主机都可以远程登录到该服务器上访问。如果要限制只有某台机器可以访问,将其换成相应的IP即可,如:

GRANT ALL PRIVILEGES ON *.* TO root@"172.168.193.25" IDENTIFIED BY "root";

第二句表示从mysql数据库的grant表中重新加载权限数据。因为MySQL把权限都放在了cache中,所以在做完更改后需要重新加载。

6、如果系统的防火墙开着(or behind a hardware firewall or NAT)你必须放开mysql使用的TCP端口,通常都是3306。

7、大小写敏感

用root帐号登录后,在/etc/my.cnf 中的[mysqld]后添加添加lower_case_table_names=1,重启MYSQL服务,这时已设置成功:不区分表名的大小写;
lower_case_table_names参数详解:
lower_case_table_names = 0 
其中 0:区分大小写,1:不区分大小写

来源:http://www.cnblogs.com/shanyou/p/3278692.html

原文地址:https://www.cnblogs.com/linn/p/5408219.html