MySQL [MariaDB] Installation and Configuration

MariaDB(MySQL)

MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可。
开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区采用分支的方式来避开这个风险。
MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。
YUM 安装
注意: 如果yum仓库是国内常用的源,那仓库中mariadb默认的版本会比官方Yum仓库低一些,所以我们要装新的mariadb需要配置回官方Yum源

Configuration official source MariaDByum

First of all

Edit files created mariadb.repo warehouse

vim /etc/yum.repos.d/MariaDB.repo

Adding repo warehouse configuration (official sources)

[mariadb]
name=MariaDB
baseurl=http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

3. When the MariaDB warehouse address is added good, you can easily install MariaDB by following his orders.

yum install -y MariaDB-server MariaDB-client

The official source because it is foreign, the installation will be very time-consuming, can be configured into the above as follows (other domestic installation source)

[mariadb]
name=MariaDB
baseurl=https://mirrors.ustc.edu.cn/mariadb/yum/10.2/centos7-amd64
gpgkey=https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1

You need to clear the cache

yum clean all
yum makecache all

Install

yum install -y MariaDB-server MariaDB-client

If you need to remove the old version, delete and then configure
uninstall and delete profiles

yum remove mariadb
rm -rf /etc/my.cnf      # 配置
rm -rf /var/lib/mysql/  # 数据

Start mariadb related commands:

# mariadb数据库的相关命令是:
systemctl start mariadb     # 启动MariaDB
systemctl stop mariadb      # 停止MariaDB
systemctl restart mariadb   # 重启MariaDB
systemctl status mariadb    # 查看运行状态
systemctl enable mariadb    # 设置开机启动

Do not use immediately after confirmation MariaDB database software program installed and successfully started . In order to ensure the safety and normal operation of the database, you need to initialize the database program operation. This initialization operation involves the following five steps.
➢ root administrator password values in the database (note that this is not the root password for the system administrator's password, the default password value here should be empty, you can simply press the Enter key).
➢ set the root password in the administrator's proprietary database.
➢ subsequently removed anonymous account and log in as root administrator from a remote database to ensure database running on industry
safety legal requirements.
➢ delete the default test database, canceled a series of test access to the database.
➢ refresh the authorization list, let initialization settings take effect immediately.

# mariadb的初始化
/usr/bin/mysql_secure_installation

When the database password is empty, press enter

Configure the following recommendations:

Enter current password for root (enter for none):   #  没密码直接回车
Set root password? [Y/n]: Y                         # 设置密码
New password: your-MariaDB-root-password
Re-enter new password: your-MariaDB-root-password
Remove anonymous users? [Y/n]: Y                    # 删除匿名账户
Disallow root login remotely? [Y/n]: n              # 是否禁止管理员从远程登录
Remove test database and access to it? [Y/n]: Y     # 删除test数据库并取消访问
Reload privilege tables now? [Y/n]: Y               # 刷新授权表,让初始化后生效

Modify database Chinese coding problem [omit this can create a database charset = utf8]
modify the configuration file (the file is not created directly)

vim /etc/my.cnf

Add the following configuration file

[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
log-error=/var/log/mysqld.log
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8

Restart the database

systemctl restart mariadb

Access to the database using the mysql command

mysql -u root -p

mysql basic operations

# 1 创建数据库
create database testmysql charset=utf8mb4;
# 2 创建表
create table qishitb (id int, name char(11));

# 3 插入数据
insert into qishitb values(1, "某某");

# 4 查看数据
select * from qishitb;

# 查看数据库的信息
\s

# 查看表的编码信息
show create table qishitb

It relates to import data into mariadb
derived database

# 导出数据库
mysqldump -u root -p123 luffy > ~/Desktop/luffy.sql

方法一
# 导入数据库
# 在命令行
mysql -u root -p123 -h 106.52.85.190 -P3306 < ./luffy.sql

方法二
# 导入数据库
source /root/backup/luffy.sql

Guess you like

Origin www.cnblogs.com/wshlym/p/11330243.html