记得安装cmake和boost

创建mysql系统账号

groupadd mysql

#增加一个名为 Mysql的用户组

useradd mysql -g mysql -M -s /sbin/nologin

#增加一个名为CentOS Mysql的用户

上传mariadb 二进制安装包到/usr/src目录下

解压 tar xf mariadbXxxxxxxxxxxxxx

先重命名成

mv mariadb-10.5.4-linux-systemd-x86_64 mariadb

移动目录到/usr/local

mv mariadb /usr/local

创建软连接

ln -sv mariadb mysql

mariadbmysql授权

chown -R mysql:mysql mysql

chown -R mysql:mysql mariadb

创建mysql数据目录

cd /

mkdir data

mkdir /data/mariadb

创建mysql日志文件

cd /data/mariadb

touch mysql-error.log

touch mysql-slow.log

安装依赖

yum -y install make gcc ncurses-devel gcc-* bzip2-* bison epel-release pcre-devel zlib zlib-devel epel-release ncurses-devel gcc-* bzip2-* bison epel-release openssl openssl-devel libtirpc-devel gcc pcre-devel zlib zlib-devel screen nano wget gcc-c++ libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel gd net-snmp-* libxml2-devel sqlite-devel libcurl-devel autoconf automake libtool lsof libaio libncurses*

定位到

cd /usr/local/mysql

执行

初始化安装

./scripts/mysql_install_db --user=mysql --datadir=/data/mariadb --basedir=/usr/local/mariadb
如提示报错
yum install libaio

echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh 

. /etc/profile.d/mysql.sh

cp /usr/local/mysql/support-files/systemd/mysql.service /usr/lib/systemd/system

接着编辑 mysql 的配置文件

cd /etc

nano my.cnf

粘贴下面的代码
指定安装路径

centos7 要注意改 路径


[mysqld]
datadir=/data/mysql
socket=/data/mysql/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=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

生成 mysql.sock 文件

cd /

systemctl enable mysql

systemctl stop mysql

systemctl start mysql

systemctl status mysql

先输入mysql 生成mysql.sock 文件

/tmp目录

查看mysql.sock是哪里的

ll

如果非/data/mysql/mysql.sock
则删除

rm -rf mysql.sock

重新建立软连接

ln -sv /data/mysql/mysql.sock /tmp/mysql.sock 

回到主目录

cd /

systemctl stop mysql

systemctl start mysql

systemctl status mysql

数据库初始化

下面这个 记得选NNNNNNN

Switch to unix_socket authentication [Y/n] n

输入

mysql_secure_installation
[root@finally etc]# 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
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'.

##########################选NNNNNNN##########################
Switch to unix_socket authentication [Y/n] n
 ... skipping.

##########################选NNNNNNN##########################

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!


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

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!

安装并测试完毕后 记得删除

这个文件

/usr/local/mysql/bin/my_print_defaults

删除后 再次运行 mysql_secure_installation 提示

FATAL ERROR: Could not find /usr/local/mysql/bin/my_print_defaults

则成功

#把执行文件bin放入 $PATH全局变量
[root@wnz ~]# vim /etc/profile.d/mysql.sh
[root@wnz ~]# cat /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
[root@wnz ~]# . /etc/profile.d/mysql.sh
[root@wnz ~]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@wnz ~]# which mysql
/usr/local/mysql/bin/mysql
————————————————
版权声明:本文为CSDN博主「小洲同学」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/wangniezhou/article/details/106740217

FLUSH PRIVILEGES;

禁止 Mariadb 无密码登录

最后修改日期: 2021年1月23日