Mariadb是MySQL的一个开源分支,主要是社区在维护,并且完全兼容MySQL,并且可以很方便的称为MySQL的替代,Mariadb的诞生是出自MySQL创始人Michael Widenius之手,命名的来源是他女儿的名字Maria,因为之前他把MySQL卖给sun公司,而sun又被oracle收购,所以MySQL也属于oracle所有,因此存在闭源的风险;而Michael Widenius开发的MariaDB作为MySQL的开源分支,很好的避免的这个潜在的问题,所以MariaDB成为了MySQL未来的替代,很多厂商也越来越关注MariaDB,并且Mariadb在很多方面的性能也要强过MySQL,像目前Windows桌面的php集成开发环境比如xampp还有linux和lnmp环境都采用MariaDB作为默认的数据库,所以从MySQL转向Mariadb也是一种趋势。
wget http://ftp.hosteurope.de/mirror/archive.mariadb.org//mariadb-10.3.12/bintar-linux-x86_64/mariadb-10.3.12-linux-x86_64.tar.gz
groupadd mysql
useradd -g mysql mysql
tar -xvf mmariadb-10.3.12-linux-x86_64.tar.gz -C /usr/local
cd /usr/local
ln -s mmariadb-10.3.12-linux-x86_64/ /usr/local/mysql
chown -R mysql:mysql /usr/local/mariadb-10.3.12-linux-x86_64/
chown -R mysql:mysql /usr/local/mysql/
echo "PATH=/usr/local/mysql/bin:$PATH" > /etc/profile
source /etc/profile
mkdir /app/mysql_data
chown -R mysql:mysql /app/mysql_data
[root@k8s-node3 mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/app/mysql_data/
Installing MariaDB/MySQL system tables in '/app/mysql_data/' ...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:
'/usr/local/mysql//bin/mysqladmin' -u root password 'new-password'
'/usr/local/mysql//bin/mysqladmin' -u root -h k8s-node3 password 'new-password'
Alternatively you can run:
'/usr/local/mysql//bin/mysql_secure_installation'
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.
You can start the MariaDB daemon with:
cd '/usr/local/mysql/' ; /usr/local/mysql//bin/mysqld_safe --datadir='/app/mysql_data/'
You can test the MariaDB daemon with mysql-test-run.pl
cd '/usr/local/mysql//mysql-test' ; perl mysql-test-run.pl
Please report any problems at http://mariadb.org/jira
The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/
[root@k8s-node3 mysql]# cat /etc/my.cnf
[mysqld]
datadir=/app/mysql_data
socket=/app/mysql_data/mysql.sock
Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
Settings user and group are ignored when systemd is used.
If you need to run mysqld under a different user or group,
customize your systemd unit file for mariadb according to the
instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/app/mysql/log/mariadb.log
pid-file=/app/mysql/pid/mariadb.pid
[mysql]
socket=/app/mysql_data/mysql.sock
#
include all files from the config directory
#
!includedir /etc/my.cnf.d
mkdir /app/mysql/{log,pid}
chown -R mysql.mysql /app/mysql/
cp /usr/local/mysql/support-files/mysql.server /lib/systemd/system/
systemctl reload
systemctl start mariadb
[root@k8s-node3 ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.3.12-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)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| log |
| mysql |
| performance_schema |
| pid |
| test |
+--------------------+
6 rows in set (0.001 sec)
MariaDB [(none)]>
[root@k8s-node3 ~]# mysql_secure_installation
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
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 MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y #设置root密码
New password:
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!
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] y #允许root远程登录
... 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.
Remove test database and access to it? [Y/n] y #删除测试库
- 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.
Reload privilege tables now? [Y/n] y #是否重新加载特权表
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
[root@k8s-node3 ~]# mysql #没有账号密码会报以下错误信息
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@k8s-node3 ~]# mysql -uroot -p12345.com #输入账号密码即可登录
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 23
Server version: 10.3.12-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)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| log |
| mysql |
| performance_schema |
| pid |
+--------------------+
5 rows in set (0.001 sec)