Mariadb二进制部署

一、Mariadb的简单介绍

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也是一种趋势。

二、Mariadb安装步骤

2.1、下载所需版本的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
2.2、创建所需用户及组
groupadd  mysql
useradd -g mysql mysql
2.3、解压压缩包倒/usr/local/
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
2.4、授权mysql目录为mysql用户所有
chown -R mysql:mysql  /usr/local/mariadb-10.3.12-linux-x86_64/
chown -R mysql:mysql  /usr/local/mysql/
2.5、配置环境变量
echo "PATH=/usr/local/mysql/bin:$PATH" > /etc/profile
source /etc/profile
2.6、创建数据目录
mkdir /app/mysql_data
chown -R mysql:mysql /app/mysql_data
2.7、初始化数据库
[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/
2.8、编写mysql配置文件my.cnf
[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
2.9、创建log及pid文件目录病授权
mkdir /app/mysql/{log,pid}
chown -R mysql.mysql /app/mysql/
2.10、复制启动文件
cp /usr/local/mysql/support-files/mysql.server /lib/systemd/system/
systemctl reload
systemctl start mariadb
2.11、登录数据库(此时所有用户都可以登录)
[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)]> 

三、加固mariadb

[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!
3.1、登录数据库(此时登录数据库需要账号密码)
[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)
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

运维那些事~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值