二进制安装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 @   小糊涂90  阅读(91)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
点击右上角即可分享
微信分享提示