二进制安装mariadb10.4

 

#下载二进制安装包(centos7系统):
[root@localhost ~]#wget http://mirrors.dotsrc.org/mariadb/mariadb-10.4.21/bintar-linux-x86_64/mariadb-10.4.21-linux-x86_64.tar.gz
#解压到安装目录/usr/local/mariadb
[root@localhost ~]# mkdir /usr/local/mariadb
[root@localhost ~]# tar zxf mariadb-10.4.21-linux-x86_64.tar.gz -C /usr/local/mariadb
[root@localhost ~]# ls /usr/local/mariadb/mariadb-10.4.21-linux-x86_64/
bin     CREDITS include         lib mysql-test README-wsrep share     support-files
COPYING docs     INSTALL-BINARY man README.md   scripts       sql-bench THIRDPARTY
#[root@localhost mariadb]# mv /usr/local/mariadb/mariadb-10.4.21-linux-x86_64/* /usr/local/mariadb/


#创建用户及组
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -s /sbin/nologin -r -g mysql mysql

#配置服务开机自启动
[root@localhost ~]# cp /usr/local/mariadb/mariadb-10.4.21-linux-x86_64/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# chmod +x /etc/init.d/mysqld
[root@localhost ~]# chkconfig --add mysqld

#新建数据目录与权限
[root@localhost ~]# mkdir -p /data/mariadb
[root@localhost ~]# chown -R mysql.mysql /data/mariadb
[root@localhost ~]# chown -R mysql.mysql /usr/local/mariadb

#准备配置文件my.cnf
[root@localhost ~]# vim /usr/local/mariadb/my.cnf
[mysqld]
#basedir=/usr/local/mariadb/ #二进制安装pass the --basedir option
datadir=/data/mariadb/
port=3306
pid-file=/data/mariadb/mysql.pid
socket=/tmp/mysql.sock

[mysqld_safe]
log-error=/data/mariadb/mysql.log

[client]
port=3306
socket=/tmp/mysql.sock
default-character-set=utf8


#数据库初始化
[root@localhost ~]# /usr/local/mariadb/scripts/mysql_install_db --defaults-file=/usr/local/mariadb/my.cnf --user=mysql --basedir=/usr/local/mariadb/ --datadir=/data/mariadb/
[root@localhost ~]# echo $?
0

#配置环境变量
[root@localhost ~]# echo "PATH=$PATH:/usr/local/mariadb/bin" > /etc/profile.d/mairadb.sh[root@localhost ~]# chmod +x /etc/profile.d/mairadb.sh
[root@localhost ~]# . /etc/profile.d/mairadb.sh

#安全模式启动设置root密码
[root@localhost data]# mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf &

[root@localhost data]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.4.21-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)]> set password=password('123456');
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.000 sec)

#安全初始化
[root@localhost data]# mysql_secure_installation --basedir=/usr/local/mariadb
print: /usr/local/mariadb/bin/my_print_defaults

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.

Enter current password for root (enter for none):
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.

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!


You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] n
... skipping.

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] n
... skipping.

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用户,密码123456登录成功
[root@localhost data]# systemctl restart mysqld
[root@localhost data]# mysql -uroot -p123456
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 10.4.21-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)]>

 

posted @ 2021-11-03 15:42  小糊涂90  阅读(74)  评论(0编辑  收藏  举报