mariaDB安装教程
mariaDB是mysql不错的替代品,安装也简单。
官方下载
为CentOS定制的MariaDB YUM源条目
复制并粘贴到/etc/yum.repos.d/ 目录下(建议文件名CentOS-MariaDB.repo)。
如:/etc/yum.repos.d/CentOS-MariaDB.repo
,文件内容如下:
# MariaDB 10.5 CentOS repository list - created 2020-09-28 13:54 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.5/centos8-amd64
module_hotfixes=1
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
配置项module_hotfixes=1是一个dnf bug的解决方案。详见MDEV-20673。
安装MariaDB
sudo dnf install MariaDB-server
两次y
然后回车
Installed:
MariaDB-client-10.5.6-1.el8.x86_64 MariaDB-common-10.5.6-1.el8.x86_64
MariaDB-server-10.5.6-1.el8.x86_64 MariaDB-shared-10.5.6-1.el8.x86_64
boost-program-options-1.66.0-7.el8.x86_64 galera-4-26.4.5-1.el8.x86_64
perl-DBI-1.641-3.module_el8.1.0+199+8f0a6bbd.x86_64 perl-Math-BigInt-1:1.9998.11-7.el8.noarch
perl-Math-Complex-1.59-416.el8.noarch socat-1.7.3.3-2.el8.x86_64
Complete!
安装完毕!
启动MariaDB
sudo systemctl start mariadb
设置为开机自启:systemctl enable mariadb
如果您还没有接受MariaDB GPG密钥,在安装过程中会提示您这样做。有关详细信息,请参阅“Installing MariaDB with yum”。
安装后配置root密码
执行mariadb-secure-installation
即可设置root密码(10.5.2之前是mysql_secure_installation
)
[root@localhost ~]# 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'.
Switch to unix_socket authentication [Y/n] n
... skipping.
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] Y
... 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!
创建远程用户并授权
创建一个远程用户:
mysql -uroot -p -A回车输入密码
create user 'jroot'@'%' identified by 'MIMA_MIMA';
GRANT ALL PRIVILEGES on *.* TO 'jroot'@'%' WITH GRANT OPTION;;
FLUSH PRIVILEGES;
其他
https://mariadb.com/kb/en/yum/
卸载Mariadb
YUM卸载:yum remove mariadb
找到lib来:rpm -qa | grep mariadb
删除找到的库:rpm -e --nodeps 库
删除遗留目录
rm -rf /etc/my.cnf
rm -rf /var/lib/mysql/
mysql 重置密码 root
service mysql stop
cd /usr/local/mysql/bin
./mysqld_safe --skip-grant-tables &
update mysql.user set password=PASSWORD('Mm@667788') where User='root';
#UPDATE mysql.user SET authentication_string=PASSWORD('Mm@667788') WHERE User='root';
flush privileges;
quit
service mysql start
create user 'jroot'@'%' identified by 'Mm@667788';
GRANT ALL PRIVILEGES on . TO 'jroot'@'%' WITH GRANT OPTION;
# GRANT ALL PRIVILEGES ON *.* TO 'jroot'@'%' IDENTIFIED BY 'Mm@667788' WITH GRANT OPTION;
FLUSH PRIVILEGES;