欢迎投稿

今日深度:

CentOS7 编译安装MariaDB,centos7mariadb

CentOS7 编译安装MariaDB,centos7mariadb


1、查看数据库配置文件

[root@i****z ~]# find -H /etc/ | grep my.c
/etc/pki/tls/certs/make-dummy-cert
/etc/pki/tls/certs/renew-dummy-cert
/etc/my.cnf
/etc/my.cnf.d
/etc/my.cnf.d/mysql-clients.cnf

2、删除数据库配置文件

[root@i****z ~]# rm -rf /etc/my.cnf /etc/my.cnf.d/
[root@i****z ~]# 

 3、查找、卸载系统自带mariadb-libs

[root@i****z ~]# rpm -qa|grep mariadb-libs
mariadb-libs-5.5.52-1.el7.x86_64

[root@i****z ~]# rpm -e mariadb-libs-5.5.52-1.el7.x86_64 --nodeps
warning: file /etc/my.cnf.d/mysql-clients.cnf: remove failed: No such file or directory
warning: file /etc/my.cnf.d: remove failed: No such file or directory
warning: file /etc/my.cnf: remove failed: No such file or directory

4、安装相关依赖包

[root@i****z ~]# yum -y install libaio libaio-devel bison bison-devel zlib-devel
[root@i****z ~]# yum -y install openssl openssl-devel ncurses ncurses-devel libcurl-devel libarchive-devel
[root@i****z ~]# yum -y install boost boost-devel cmake cmake-devel

5、创建用户和组

[root@i****z ~]# groupadd -r mysql
[root@i****z ~]# useradd -g mysql -s /sbin/nologin mysql

6、创建安装目录和数据目录,MariaDB官网下载https://downloads.mariadb.org/

[root@i****z ~]# mkdir /usr/local/mysql

[root@i****z ~]# mkdir -p /data/mysql
# 下面一句表示创建数据库,在安装完成后,初始化数据库的时候会自动加载data、bin_log等库,可以不使用
[root@i****z ~]# mkdir -pv /data/mysql/{data,bin_log,run,log,tmp}

[root@i****z ~]# chown -R mysql:mysql /usr/local/mysql/
[root@i****z ~]# chown -R mysql:mysql /data/mysql/
[root@i****z ~]# cd /usr/local/mysql/
[root@i****z mysql]# wget -O mariadb-10.3.9.tar.gz https://downloads.mariadb.org/interstitial/mariadb-10.3.9/source/mariadb-10.3.9.tar.gz/from/http%3A//mirrors.neusoft.edu.cn/mariadb/?serve
[root@i****z mysql]# tar -zxvf mariadb-10.3.9.tar.gz 
[root@i****z mysql]# cd mariadb-10.3.9 

7、创建编译文件并编译(如果在编译过程中提示内存不足,请查看文章末尾内容)

[root@i****z mariadb-10.3.9]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DSYSCONFDIR=/etc \
-DWITHOUT_TOKUDB=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STPRAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWIYH_READLINE=1 \
-DWIYH_SSL=system \
-DVITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci

# 说明
# -DCMAKE_INSTALL_PREFIX=/usr/local/mysql    安装根目录
# -DMYSQL_DATADIR=/data/mysql                数据存储目录
# -DSYSCONFDIR=/etc                          配置文件存放目录
# -DMYSQL_UNIX_ADDR=/tmp/mysql.sock          临时文件存放目录
# -DWITHOUT_TOKUDB=1                         tokudb引擎不支持
# -DWITH_INNOBASE_STORAGE_ENGINE=1           innoDB引擎支持
# -DWITH_ARCHIVE_STPRAGE_ENGINE=1            archive引擎支持
# -DWITH_BLACKHOLE_STORAGE_ENGINE=1          blackhole引擎支持
# -DWIYH_READLINE=1                          readline库
# -DWIYH_SSL=system                          使用系统自带的ssl库
# -DVITH_ZLIB=system                         使用系统自带的zlib库
# -DWITH_LIBWRAP=0                           禁用libwrap库
# -DDEFAULT_CHARSET=utf8                     默认字符集
# -DDEFAULT_COLLATION=utf8_general_ci        默认字符集校对

[root@i****z mariadb-10.3.9]# make && make install
# 编译过程有点漫长......

# 如果报以下错误,说明内存小,编译失败(安装MySQL遇到过)
c++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
make[2]: *** [sql/CMakeFiles/sql_gis.dir/gis/crosses.cc.o] Error 4
make[1]: *** [sql/CMakeFiles/sql_gis.dir/all] Error 2
make: *** [all] Error 2

8、切换至安装目录,执行生成数据库操作,添加开机启动,添加系统服务

[root@i****z mariadb-10.3.9]# cd /usr/local/mysql/
[root@i****z mysql]# scripts/mysql_install_db --datadir=/data/mysql --user=mysql
[root@i****z mysql]# cp support-files/mysql.server /etc/init.d/mysqld 
[root@i****z mariadb-10.3.9]# cd /etc/init.d/
[root@i****z init.d]# chkconfig --add mysqld
[root@i****z init.d]# chkconfig mysqld on

9、添加环境变量

[root@i****z mysql]# vim /etc/profile.d/mysql.sh
# 输入内容:
export PATH=$PATH:/usr/local/mysql/bin/

[root@i****z mysql]# chmod 777 /etc/profile.d/mysql.sh 
[root@i****z mysql]# source /etc/profile.d/mysql.sh 

10、连接测试

[root@i****z mysql]# mysql -u -p
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.3.9-MariaDB Source distribution

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 |
| test               |
+--------------------+
2 rows in set (0.000 sec)

MariaDB [(none)]> exit
Bye
[root@i****z mysql]# 

11、初始化mariadb

[root@i****z mysql]# /usr/local/mysql/bin/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.

# 设置root密码
Set root password? [Y/n] y
New password: 
Re-enter new password: 
Sorry, passwords do not match.

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.

# 禁止root用户远程登录
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.

# 删除test数据表并访问
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!

# 初始化完成,再次连接测试
[root@i****z mysql]# mysql -u -p
ERROR 1045 (28000): Access denied for user '-p'@'localhost' (using password: NO)
[root@i****z mysql]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 21
Server version: 10.3.9-MariaDB Source distribution

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 |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.000 sec)

# 使用mysql库
MariaDB [(none)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

# 查看表
MariaDB [mysql]> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| column_stats              |
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
| gtid_slave_pos            |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| index_stats               |
| innodb_index_stats        |
| innodb_table_stats        |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| roles_mapping             |
| servers                   |
| slow_log                  |
| table_stats               |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| transaction_registry      |
| user                      |
+---------------------------+
31 rows in set (0.000 sec)

# 查看用户
MariaDB [mysql]> select * from user;
+-----------+------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+---------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+--------+-----------------------+------------------+---------+--------------+--------------------+
| Host      | User | Password                                  | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv | Repl_slave_priv | Repl_client_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Create_user_priv | Event_priv | Trigger_priv | Create_tablespace_priv | Delete_history_priv | ssl_type | ssl_cipher | x509_issuer | x509_subject | max_questions | max_updates | max_connections | max_user_connections | plugin | authentication_string | password_expired | is_role | default_role | max_statement_time |
+-----------+------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+---------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+--------+-----------------------+------------------+---------+--------------+--------------------+
| localhost | root | *F2**********************************A5D2 | Y           | Y           | Y           | Y           | Y           | Y         | Y           | Y             | Y            | Y         | Y          | Y               | Y          | Y          | Y            | Y          | Y                     | Y                | Y            | Y               | Y                | Y                | Y              | Y                   | Y                  | Y                | Y          | Y            | Y                      | Y                   |          |            |             |              |             0 |           0 |               0 |                    0 |        |                       | N                | N       |              |           0.000000 |
| 127.0.0.1 | root | *F2**********************************A5D2 | Y           | Y           | Y           | Y           | Y           | Y         | Y           | Y             | Y            | Y         | Y          | Y               | Y          | Y          | Y            | Y          | Y                     | Y                | Y            | Y               | Y                | Y                | Y              | Y                   | Y                  | Y                | Y          | Y            | Y                      | Y                   |          |            |             |              |             0 |           0 |               0 |                    0 |        |                       | N                | N       |              |           0.000000 |
| ::1       | root | *F2**********************************A5D2 | Y           | Y           | Y           | Y           | Y           | Y         | Y           | Y             | Y            | Y         | Y          | Y               | Y          | Y          | Y            | Y          | Y                     | Y                | Y            | Y               | Y                | Y                | Y              | Y                   | Y                  | Y                | Y          | Y            | Y                      | Y                   |          |            |             |              |             0 |           0 |               0 |                    0 |        |                       | N                | N       |              |           0.000000 |
+-----------+------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+---------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+--------+-----------------------+------------------+---------+--------------+--------------------+
3 rows in set (0.000 sec)

# 设置远程访问数据库的账号密码
MariaDB [mysql]> grant all privileges on *.* to 'root'@'%' identified by '密码' with grant option;
Query OK, 0 rows affected (0.000 sec)

MariaDB [mysql]> select * from user;
+-----------+------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+---------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+--------+-----------------------+------------------+---------+--------------+--------------------+
| Host      | User | Password                                  | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv | Repl_slave_priv | Repl_client_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Create_user_priv | Event_priv | Trigger_priv | Create_tablespace_priv | Delete_history_priv | ssl_type | ssl_cipher | x509_issuer | x509_subject | max_questions | max_updates | max_connections | max_user_connections | plugin | authentication_string | password_expired | is_role | default_role | max_statement_time |
+-----------+------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+---------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+--------+-----------------------+------------------+---------+--------------+--------------------+
| localhost | root | *F2**********************************A5D2 | Y           | Y           | Y           | Y           | Y           | Y         | Y           | Y             | Y            | Y         | Y          | Y               | Y          | Y          | Y            | Y          | Y                     | Y                | Y            | Y               | Y                | Y                | Y              | Y                   | Y                  | Y                | Y          | Y            | Y                      | Y                   |          |            |             |              |             0 |           0 |               0 |                    0 |        |                       | N                | N       |              |           0.000000 |
| 127.0.0.1 | root | *F2**********************************A5D2 | Y           | Y           | Y           | Y           | Y           | Y         | Y           | Y             | Y            | Y         | Y          | Y               | Y          | Y          | Y            | Y          | Y                     | Y                | Y            | Y               | Y                | Y                | Y              | Y                   | Y                  | Y                | Y          | Y            | Y                      | Y                   |          |            |             |              |             0 |           0 |               0 |                    0 |        |                       | N                | N       |              |           0.000000 |
| ::1       | root | *F2**********************************A5D2 | Y           | Y           | Y           | Y           | Y           | Y         | Y           | Y             | Y            | Y         | Y          | Y               | Y          | Y          | Y            | Y          | Y                     | Y                | Y            | Y               | Y                | Y                | Y              | Y                   | Y                  | Y                | Y          | Y            | Y                      | Y                   |          |            |             |              |             0 |           0 |               0 |                    0 |        |                       | N                | N       |              |           0.000000 |
| %         | root | *6C**********************************8BA4 | Y           | Y           | Y           | Y           | Y           | Y         | Y           | Y             | Y            | Y         | Y          | Y               | Y          | Y          | Y            | Y          | Y                     | Y                | Y            | Y               | Y                | Y                | Y              | Y                   | Y                  | Y                | Y          | Y            | Y                      | Y                   |          |            |             |              |             0 |           0 |               0 |                    0 |        |                       | N                | N       |              |           0.000000 |
+-----------+------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+---------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+--------+-----------------------+------------------+---------+--------------+--------------------+
4 rows in set (0.000 sec)

MariaDB [mysql]> exit
Bye
[root@i****z mysql]# 

12、安装完成

13、本地通过软件连接数据库(连接成功)、服务器重启后任意目录进入数据库(mysql -u root -p)(测试成功)


如果编译时提示内存不足,请查看以下内容,更改内存

# 获取要增加的2G的SWAP文件块
[root@i****z mariadb-10.3.9]# dd if=/dev/zero of=/swapfile bs=1k count=2048000
2048000+0 records in
2048000+0 records out
2097152000 bytes (2.1 GB) copied, 17.8827 s, 117 MB/s

# 创建SWAP文件
[root@i****z mariadb-10.3.9]# mkswap /swapfile 
Setting up swapspace version 1, size = 2047996 KiB
no label, UUID=bd05dc90-ab37-483c-98db-5e98c92ae814

# 创建SWAP文件激活
[root@i****z mariadb-10.3.9]# swapon /swapfile 
swapon: /swapfile: insecure permissions 0644, 0600 suggested.

# 查看swap信息是否正确
[root@i****z mariadb-10.3.9]# swapon -s
Filename               Type       Size       Used     Priority
/swapfile              file     2047996       0          -1

# 添加到fstab文件中让系统引导时自动启动
[root@i****z mariadb-10.3.9]# echo '/var/swapfile swap swap defaults 0 0' >> /etc/fstab 

# 再次执行之前的编译步骤

# 编译完成后,如果想切换回原来的分区,执行以下命令
[root@i****z mariadb-10.3.9]# swapoff /swapfile
[root@i****z mariadb-10.3.9]# rm -fr /swapfile

www.htsjk.Com true http://www.htsjk.com/mariadb/32149.html NewsArticle CentOS7 编译安装MariaDB,centos7mariadb 1、查看数据库配置文件 [root@i****z ~]# find -H /etc/ | grep my.c/etc/pki/tls/certs/make-dummy-cert/etc/pki/tls/certs/renew-dummy-cert/etc/my.cnf/etc/my.cnf.d/etc/my.cnf.d/mysql-clients....
相关文章
    暂无相关文章
评论暂时关闭