centos7(Linux)系统yum安装MariaDB10.4
Add repository to CentOS 7:
[root@localhost ~]# sudo tee /etc/yum.repos.d/mariadb.repo<<EOF
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.5/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF
上面的是官方的包,在国内下载超级慢,还可能失败,经过我这边测试,得需要好几个小时,只有即KB/s,还是下面的阿里云的源好一些,不到1分钟完事。注意,当你更换源之后,要执行一遍
yum clean all 和yum makecache,用于清除以前的源的本地缓存信息,这些信息就包括这些源对应的远程的包列表(metadata),从而yum缓存在本地后直接在本地查询是否某个源包含某些包。我们用yum clean all清除以前的源对应的数据,然后makecahce重新拉取现有源对应的远程包数据。
[root@localhost ~]# sudo tee /etc/yum.repos.d/mariadb.repo<<EOF
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.5/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF
上面的是官方的包,在国内下载超级慢,还可能失败,经过我这边测试,得需要好几个小时,只有即KB/s,还是下面的阿里云的源好一些,不到1分钟完事。注意,当你更换源之后,要执行一遍
yum clean all 和yum makecache,用于清除以前的源的本地缓存信息,这些信息就包括这些源对应的远程的包列表(metadata),从而yum缓存在本地后直接在本地查询是否某个源包含某些包。我们用yum clean all清除以前的源对应的数据,然后makecahce重新拉取现有源对应的远程包数据。
[root@localhost ~]# sudo tee
/etc/yum.repos.d/mariadb.repo<<EOF
[mariadb]
name = MariaDB
baseurl = https://mirrors.aliyun.com/mariadb/yum/10.4/centos7-amd64/
gpgkey=https://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF
[root@localhost ~]#cat /etc/yum.repos.d/mariadb.repo
[mariadb]
name = MariaDB
baseurl = https://mirrors.aliyun.com/mariadb/yum/10.4/centos7-amd64/
gpgkey=https://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF
[root@localhost ~]#cat /etc/yum.repos.d/mariadb.repo
Confirm the repository is working by updating cache.
[root@localhost ~]# sudo yum makecache
List available repositories:我们可以看到库中有了mariadb
[root@localhost ~]# yum repolist
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository contrib is listed more than once in the configuration
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* remi-php70: mirrors.tuna.tsinghua.edu.cn
* remi-php71: mirrors.tuna.tsinghua.edu.cn
* remi-php73: mirrors.tuna.tsinghua.edu.cn
* remi-safe: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.aliyun.com
* webtatic: us-east.repo.webtatic.com
repo id repo name status
base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 10,070
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,424
extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 412
mariadb MariaDB 88
nginx/x86_64 nginx repo 190
remi-php70 Remi's PHP 7.0 RPM repository for Enterprise Linux 7 - x86_64 426
remi-php71 Remi's PHP 7.1 RPM repository for Enterprise Linux 7 - x86_64 439
remi-php73 Remi's PHP 7.3 RPM repository for Enterprise Linux 7 - x86_64 376
remi-safe Safe Remi's RPM repository for Enterprise Linux 7 - x86_64 3,841
updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 945
webtatic/x86_64 Webtatic Repository EL7 - x86_64 725
repolist: 30,936
[root@localhost ~]#yum install MariaDB-server MariaDB-client
[root@localhost ~]# rpm -qi MariaDB-server
Name : MariaDB-server
Version : 10.4.12
Release : 1.el7.centos
Architecture: x86_64
Install Date: Mon 03 Aug 2020 07:11:44 AM EDT
Group : Applications/Databases
Size : 132246402
License : GPLv2
Signature : DSA/SHA1, Mon 27 Jan 2020 04:52:24 PM EST, Key ID cbcb082a1bb943db
Source RPM : MariaDB-server-10.4.12-1.el7.centos.src.rpm
Build Date : Sun 26 Jan 2020 04:22:58 PM EST
Build Host : centos73-amd64
Relocations : (not relocatable)
Vendor : MariaDB Foundation
URL : http://mariadb.org
Summary : MariaDB: a very fast and robust SQL database server
Description :
MariaDB: a very fast and robust SQL database server
[root@localhost ~]# sudo yum makecache
List available repositories:我们可以看到库中有了mariadb
[root@localhost ~]# yum repolist
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository contrib is listed more than once in the configuration
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* remi-php70: mirrors.tuna.tsinghua.edu.cn
* remi-php71: mirrors.tuna.tsinghua.edu.cn
* remi-php73: mirrors.tuna.tsinghua.edu.cn
* remi-safe: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.aliyun.com
* webtatic: us-east.repo.webtatic.com
repo id repo name status
base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 10,070
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,424
extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 412
mariadb MariaDB 88
nginx/x86_64 nginx repo 190
remi-php70 Remi's PHP 7.0 RPM repository for Enterprise Linux 7 - x86_64 426
remi-php71 Remi's PHP 7.1 RPM repository for Enterprise Linux 7 - x86_64 439
remi-php73 Remi's PHP 7.3 RPM repository for Enterprise Linux 7 - x86_64 376
remi-safe Safe Remi's RPM repository for Enterprise Linux 7 - x86_64 3,841
updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 945
webtatic/x86_64 Webtatic Repository EL7 - x86_64 725
repolist: 30,936
[root@localhost ~]#yum install MariaDB-server MariaDB-client
[root@localhost ~]# rpm -qi MariaDB-server
Name : MariaDB-server
Version : 10.4.12
Release : 1.el7.centos
Architecture: x86_64
Install Date: Mon 03 Aug 2020 07:11:44 AM EDT
Group : Applications/Databases
Size : 132246402
License : GPLv2
Signature : DSA/SHA1, Mon 27 Jan 2020 04:52:24 PM EST, Key ID cbcb082a1bb943db
Source RPM : MariaDB-server-10.4.12-1.el7.centos.src.rpm
Build Date : Sun 26 Jan 2020 04:22:58 PM EST
Build Host : centos73-amd64
Relocations : (not relocatable)
Vendor : MariaDB Foundation
URL : http://mariadb.org
Summary : MariaDB: a very fast and robust SQL database server
Description :
MariaDB: a very fast and robust SQL database server
It is GPL v2 licensed, which means you can use the it free of charge under
the
conditions of the GNU General Public License Version 2 (http://www.gnu.org/licenses/).
conditions of the GNU General Public License Version 2 (http://www.gnu.org/licenses/).
MariaDB documentation can be found at https://mariadb.com/kb
MariaDB bug reports should be submitted through https://jira.mariadb.org
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# rpm -qi MariaDB-client
Name : MariaDB-client
Version : 10.4.12
Release : 1.el7.centos
Architecture: x86_64
Install Date: Mon 03 Aug 2020 07:11:34 AM EDT
Group : Applications/Databases
Size : 62642831
License : GPLv2
Signature : DSA/SHA1, Mon 27 Jan 2020 04:52:21 PM EST, Key ID cbcb082a1bb943db
Source RPM : MariaDB-client-10.4.12-1.el7.centos.src.rpm
Build Date : Sun 26 Jan 2020 04:19:39 PM EST
Build Host : centos73-amd64
Relocations : (not relocatable)
Vendor : MariaDB Foundation
URL : http://mariadb.org
Summary : MariaDB: a very fast and robust SQL database server
Description :
MariaDB: a very fast and robust SQL database server
MariaDB bug reports should be submitted through https://jira.mariadb.org
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# rpm -qi MariaDB-client
Name : MariaDB-client
Version : 10.4.12
Release : 1.el7.centos
Architecture: x86_64
Install Date: Mon 03 Aug 2020 07:11:34 AM EDT
Group : Applications/Databases
Size : 62642831
License : GPLv2
Signature : DSA/SHA1, Mon 27 Jan 2020 04:52:21 PM EST, Key ID cbcb082a1bb943db
Source RPM : MariaDB-client-10.4.12-1.el7.centos.src.rpm
Build Date : Sun 26 Jan 2020 04:19:39 PM EST
Build Host : centos73-amd64
Relocations : (not relocatable)
Vendor : MariaDB Foundation
URL : http://mariadb.org
Summary : MariaDB: a very fast and robust SQL database server
Description :
MariaDB: a very fast and robust SQL database server
It is GPL v2 licensed, which means you can use the it free of charge under
the
conditions of the GNU General Public License Version 2 (http://www.gnu.org/licenses/).
conditions of the GNU General Public License Version 2 (http://www.gnu.org/licenses/).
MariaDB documentation can be found at https://mariadb.com/kb
MariaDB bug reports should be submitted through https://jira.mariadb.org
[root@localhost ~]# systemctl start mariadb
To enable the service to be started when the server is rebooted use the following command:
#开机启动
[root@localhost ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/mysql.service to /usr/lib/systemd/system/mariadb.service.
Created symlink from /etc/systemd/system/mysqld.service to /usr/lib/systemd/system/mariadb.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
MariaDB bug reports should be submitted through https://jira.mariadb.org
[root@localhost ~]# systemctl start mariadb
To enable the service to be started when the server is rebooted use the following command:
#开机启动
[root@localhost ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/mysql.service to /usr/lib/systemd/system/mariadb.service.
Created symlink from /etc/systemd/system/mysqld.service to /usr/lib/systemd/system/mariadb.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@localhost ~]# systemctl status mariadb
● mariadb.service - MariaDB 10.4.12 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/mariadb.service.d
└─migrated-from-my.cnf-settings.conf
Active: active (running) since Mon 2020-08-03 07:20:28 EDT; 3min 10s ago
Docs: man:mysqld(8)
https://mariadb.com/kb/en/library/systemd/
Main PID: 22229 (mysqld)
Status: "Taking your SQL requests now..."
CGroup: /system.slice/mariadb.service
└─22229 /usr/sbin/mysqld
● mariadb.service - MariaDB 10.4.12 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/mariadb.service.d
└─migrated-from-my.cnf-settings.conf
Active: active (running) since Mon 2020-08-03 07:20:28 EDT; 3min 10s ago
Docs: man:mysqld(8)
https://mariadb.com/kb/en/library/systemd/
Main PID: 22229 (mysqld)
Status: "Taking your SQL requests now..."
CGroup: /system.slice/mariadb.service
└─22229 /usr/sbin/mysqld
Aug 03 07:20:27 localhost.localdomain mysqld[22229]: 2020-08-03 7:20:27 0
[Note] InnoDB: 10.4.12 started; log sequence number 60972; transaction id
21
Aug 03 07:20:27 localhost.localdomain mysqld[22229]: 2020-08-03 7:20:27 0 [Note] Plugin 'FEEDBACK' is disabled.
Aug 03 07:20:27 localhost.localdomain mysqld[22229]: 2020-08-03 7:20:27 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
Aug 03 07:20:27 localhost.localdomain mysqld[22229]: 2020-08-03 7:20:27 0 [Note] InnoDB: Buffer pool(s) load completed at 200803 7:20:27
Aug 03 07:20:27 localhost.localdomain mysqld[22229]: 2020-08-03 7:20:27 0 [Note] Server socket created on IP: '::'.
Aug 03 07:20:27 localhost.localdomain mysqld[22229]: 2020-08-03 7:20:27 0 [Note] Reading of all Master_info entries succeeded
Aug 03 07:20:27 localhost.localdomain mysqld[22229]: 2020-08-03 7:20:27 0 [Note] Added new Master_info '' to hash table
Aug 03 07:20:27 localhost.localdomain mysqld[22229]: 2020-08-03 7:20:27 0 [Note] /usr/sbin/mysqld: ready for connections.
Aug 03 07:20:28 localhost.localdomain mysqld[22229]: Version: '10.4.12-MariaDB' socket: '/var/lib/mysql/mysql.sock' port: 3306 MariaDB Server
Aug 03 07:20:28 localhost.localdomain systemd[1]: Started MariaDB 10.4.12 database server.
Aug 03 07:20:27 localhost.localdomain mysqld[22229]: 2020-08-03 7:20:27 0 [Note] Plugin 'FEEDBACK' is disabled.
Aug 03 07:20:27 localhost.localdomain mysqld[22229]: 2020-08-03 7:20:27 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
Aug 03 07:20:27 localhost.localdomain mysqld[22229]: 2020-08-03 7:20:27 0 [Note] InnoDB: Buffer pool(s) load completed at 200803 7:20:27
Aug 03 07:20:27 localhost.localdomain mysqld[22229]: 2020-08-03 7:20:27 0 [Note] Server socket created on IP: '::'.
Aug 03 07:20:27 localhost.localdomain mysqld[22229]: 2020-08-03 7:20:27 0 [Note] Reading of all Master_info entries succeeded
Aug 03 07:20:27 localhost.localdomain mysqld[22229]: 2020-08-03 7:20:27 0 [Note] Added new Master_info '' to hash table
Aug 03 07:20:27 localhost.localdomain mysqld[22229]: 2020-08-03 7:20:27 0 [Note] /usr/sbin/mysqld: ready for connections.
Aug 03 07:20:28 localhost.localdomain mysqld[22229]: Version: '10.4.12-MariaDB' socket: '/var/lib/mysql/mysql.sock' port: 3306 MariaDB Server
Aug 03 07:20:28 localhost.localdomain systemd[1]: Started MariaDB 10.4.12 database server.
[root@localhost ~]# firewall-cmd --add-service=mysql --permanent
[root@localhost ~]# firewall-cmd --reload
#查看mariadb配置文件位置,在/etc/my.cnf.d/server.cnf
[root@localhost ~]# rpm -ql MariaDB-server|grep etc
/etc/logrotate.d/mysql
/etc/my.cnf.d
/etc/my.cnf.d/enable_encryption.preset
/etc/my.cnf.d/server.cnf
/etc/security/user_map.conf
[root@localhost ~]#
修改在/etc/my.cnf.d/server.cnf下面的监听地址,即仅仅允许某个固定ip的来源的请求,其他拒绝,也可以不修改,主要是保证安全性
For remote connection to work the service should be listening on an IP address and not localhost loopback interface.
For remote connection to work the service should be listening on an IP address and not localhost loopback interface.
# Listen on specific IP address in the
server
bind-address=172.21.200.12
# Listen on all available interfaces
bind-address=0.0.0.0
bind-address=172.21.200.12
# Listen on all available interfaces
bind-address=0.0.0.0
Step 安全: Secure MariaDB Database on CentOS 8 | CentOS 7 这一段是为了mysql的安全进行的一些操作,这个很便捷
一般我们刚刚安装好数据库后,为了安全考虑我们应该做如下处理:
1.删除匿名账户登录
2.修改root的密码,因为默认为空
我们可以登录后用grant命令手动修改,也可以用下面的mysql_secure_installation进行配置(应该是没问题,但是我这边2020年8月3日20:04:12测试,命名禁止了匿名账户,但是还是可以登录,不知道为何。)
There is a script provided for hardening MariaDB database server. The
script helps you to:
Set root password
Remove anonymous database users
Disallow remote database login as root user
Remove test databases
To start the database hardening process run the command below.
Remove anonymous database users
Disallow remote database login as root user
Remove test databases
To start the database hardening process run the command below.
[root@localhost ~]# sudo mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the
current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
OK, successfully used password, moving on...
Setting the root password or using the unix_socket ensures that
nobody
can log into the MariaDB root user without the proper authorisation.
can log into the MariaDB root user without the proper authorisation.
You already have your root account protected, so you can safely answer
'n'.
Switch to unix_socket authentication [Y/n] y
Enabled successfully!
Reloading privilege tables..
... Success!
Enabled successfully!
Reloading privilege tables..
... Success!
You already have your root account protected, so you can safely answer 'n'.
Change the root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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!
... Success!
Normally, root should only be allowed to connect from 'localhost'.
This
ensures that someone cannot guess at the root password from the network.
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
... Success!
... Success!
By default, MariaDB 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.
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] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so
far
will take effect immediately.
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your
MariaDB
installation should now be secure.
installation should now be secure.
Thanks for using MariaDB!
Test login as root user without password:
Test login as root user without password:
# mysql -u root <ENTER>
You should get an access denied error:
You should get an access denied error:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
Now try as root user and provide the pasword:
Now try as root user and provide the pasword:
# mysql -u root -p
Enter password: <ENTER-PASSWORD>
Welcome to the MariaDB monitor. Commands end with ; or g.
Your MariaDB connection id is 24
Server version: 10.5.4-MariaDB MariaDB Server
Enter password: <ENTER-PASSWORD>
Welcome to the MariaDB monitor. Commands end with ; or g.
Your MariaDB connection id is 24
Server version: 10.5.4-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or 'h' for help. Type 'c' to clear the current input
statement.
MariaDB [(none)]> SELECT VERSION();
+----------------+
| VERSION() |
+----------------+
| 10.5.4-MariaDB |
+----------------+
1 row in set (0.001 sec)
+----------------+
| VERSION() |
+----------------+
| 10.5.4-MariaDB |
+----------------+
1 row in set (0.001 sec)
MariaDB [(none)]> QUIT
Bye
Your database server is now ready for use. The only additional setting that you may require is tuning it to optimal performance depending on your application requirements and use case. This is beyond the scope of this guide.
Bye
Your database server is now ready for use. The only additional setting that you may require is tuning it to optimal performance depending on your application requirements and use case. This is beyond the scope of this guide.
Video courses on databases.
一般情况你是需要远程登录的,可以新建一个远程登录账户 可以远程navacate登录grant all on *.* to 'root'@'%' identified by '123456wer' with grant
option;