Linux CentOS7.3系统中 源码安装MariaDB数据库流程记录

1、删除CentOS7.3默认数据库配置文件

查看默认数据库配置文件

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

删除默认数据库配置文件

  1. [root@localhost ~]# rm -rf /etc/my.cnf /etc/my.cnf.d/

再次查看默认数据库配置文件

  1. [root@localhost ~]# find -H /etc/ | grep my.c/etc/pki/tls/certs/make-dummy-cert/etc/pki/tls/certs/renew-dummy-cert
到目前为止, 系统最小化安装自带的数据库配置文件已经删除干净了!

2、卸载系统自带mariadb-libs

查询和卸载

  1. [root@localhost ~]# rpm -qa|grep mariadb-libs
  2. mariadb-libs-5.5.52-1.el7.x86_64
  3. [root@localhost ~]# rpm -e mariadb-libs-5.5.52-1.el7.x86_64 --nodeps

安装相关包

  1. [root@localhost ~]# yum -y install gcc gcc-c++ cmake make perl libaio libaio-devel kernel-devel pcre-devel bison bison-devel zlib-devel openssl openssl-devel ncurses ncurses-devel libcurl-devel kernel-headers libarchive-devel boost boost-devel lsof

3、创建家目录存放软件包目录

  1. [root@localhost ~]# mkdir /usr/local/soft
  2. [root@localhost ~]# cd /usr/local/soft

4、 MariaDB官网复制源码包链接地址并下载解压

  1. [root@localhost soft]# wget https://downloads.mariadb.org/interstitial/mariadb-10.2.6/source/mariadb-10.2.6.tar.gz
  2. [root@localhost soft]# tar -zxvf mariadb-10.2.6.tar.gz

5、创建MariaDB安装目录、数据库存放目录、建立用户和目录

这里提前预定MariaDB的安装目录为/usr/local/mysql并且数据库目录为/data/mysql,这里要建立系统用户及组和数据库存放目录,并且将数据库存放目录赋予mysql用户及组权限,操作如下:

请注意特别说明一下:这里说的数据库目录是指的具体数据库存储文件, 而不是安装文件!

创建系统用户mysql并加入到mysql系统用户组

  1. [root@localhost soft]# groupadd -r mysql
  2. [root@localhost soft]# useradd -r -g mysql -s /sbin/nologin -d /usr/local/mysql -M mysql

以下是上面创建系统用户mysql的各个参数说明:

-r: 添加系统用户( 这里指将要被创建的系统用户mysql )
-g: 指定要创建的用户所属组( 这里指添加到新系统用户mysql到mysql系统用户组 )
-s: 新系统帐户的登录shell( /sbin/nologin 这里设置为将要被创建系统用户mysql不能用来登录系统 )
-d: 新帐户的主目录( 这里指定将要被创建的系统用户mysql的家目录为 /usr/local/mysql )
-M: 不要创建用户的主目录( 也就是说将要被创建的系统用户mysql不会在 /home 目录下创建 mysql 家目录 )

创建maria安装目录、创建数据库存放目录、改变数据库存放目录所属用户及组为 mysql:mysql

  1. [root@localhost soft]# mkdir -p /usr/local/mysql
  2. [root@localhost soft]# mkdir -p /data/mysql
  3. [root@localhost soft]# chown -R mysql:mysql /data/mysql
执行编译安装
  1. >进入到解压后的源码包文件夹
  2. [root@localhost soft]# cd mariadb-10.2.6
  3. > 输入编译参数
  4. cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
  5. -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_LOBWRAP=0 \ -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci

如果编译失败请删除CMakeCache.txt
[root@localhost soft]# rm -f CMakeCache.txt
让指令重新执行,否则每次读取这个文件,命令修改正确也是报错
cmake没问题,可以编译并且安装了: make && make install 时间会有点长根据个人机器吧,你可以干别的事情去!

  1. [root@localhost soft]# make && make install

执行完成也就是安装完成了, 不过请注意, 这只是安装了, 并没有启动, 启动不成功等于没安装, 不能用也是徒劳无功不是?

6、配置MariaDB

  1. > 进入到 MariaDB 安装目录
  2. [root@localhost ~]# cd /usr/local/mysql/
  3. > 使用 `mysql` 用户执行脚本, 安装数据库到数据库存放目录
  4. [root@localhost mysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mysql
  5. > 输出以下信息:
  6. Installing MariaDB/MySQL system tables in '/data/mysql' ...
  7. OKTo start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your system
  8. PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !To do so, start the server, then issue the following commands:'./bin/mysqladmin' -u root password 'new-password''./bin/mysqladmin' -u root -h localhost.localdomain password 'new-password'Alternatively you can run:'./bin/mysql_secure_installation'which will also give you the option of removing the test
  9. databases and anonymous user created by default. This isstrongly recommended for production servers.
  10. See the MariaDB Knowledgebase at http://mariadb.com/kb or theMySQL manual for more instructions.
  11. You can start the MariaDB daemon with:
  12. cd '.' ; ./bin/mysqld_safe --datadir='/data/maria'You can test the MariaDB daemon with mysql-test-run.pl
  13. cd './mysql-test' ; perl mysql-test-run.pl
  14. Please report any problems at http://mariadb.org/jiraThe latest information about MariaDB is available at http://mariadb.org/.You can find additional information about the MySQL part at:
  15. http://dev.mysql.comConsider joining MariaDB's strong and vibrant community:
  16. https://mariadb.org/get-involved/

复制MariaDB配置文件到/etc目录

  1. > 进行到 MariaDB 安装目录
  2. [root@localhost ~]# cd /usr/local/mysql/
  3. > 拷贝support-files目录下的文件my-large.cnf到/etc目录并重命名为my.cnf
  4. [root@localhost mysql]# cp support-files/my-large.cnf /etc/my.cnf

7、 创建启动脚本

  1. [root@localhost mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld

8、 启动mysqld服务

  1. [root@localhost mysql]# /etc/rc.d/init.d/mysqld start

9、配置环境变量, 以便在任何目录下输入mysql

  1. [root@localhost mysql]# vim /etc/profile.d/mysql.sh> 输入以下内容
  2. export PATH=$PATH:/usr/local/mysql/bin/> 保存并退出:wq> 为脚本赋于可执行权限
  3. [root@localhost mysql]# chmod 0777 /etc/profile.d/mysql.sh> 进行mysql.sh脚本所在目录, 并执行脚本, 以立即生效环境变量
  4. [root@localhost mysql]# source /etc/profile.d/mysql.sh

10、初始化MariaDB

  1. > 运行MariaDB初始化脚本
  2. [root@localhost mysql]# ./bin/mysql_secure_installation> 以下提示:
  3. Enter current password for root (enter for none):
  4. //输入当前root密码(没有输入)
  5. Set root password? [Y/n] // 设置root密码?(是/否)
  6. New password: // 输入新root密码
  7. Re-enter new password: //确认输入root密码
  8. Password updated successfully! //密码更新成功
  9. By default, a MariaDB installation has an anonymous user, allowing anyoneto log into MariaDB without having to have a user account created forthem. This is intended only for testing, and to make the installation
  10. go a bit smoother. You should remove them before moving into a
  11. production environment.
  12. 默认情况下,MariaDB安装有一个匿名用户,
  13. 允许任何人登录MariaDB而他们无需创建用户帐户。
  14. 这个目的是只用于测试,安装去更平缓一些。
  15. 你应该进入前删除它们生产环境。
  16. Remove anonymous users? [Y/n] 删除匿名用户?(是/否)
  17. Normally, root should only be allowed to connect from 'localhost'. Thisensures that someone cannot guess at the root password from the network.
  18. 通常情况下,root只应允许从localhost连接。
  19. 这确保其他用户无法从网络猜测root密码。
  20. Disallow root login remotely? [Y/n] 不允许root登录远程?(是/否)By default, MariaDB comes with a database named 'test' that anyone canaccess. This is also intended only for testing, and should be removed
  21. before moving into a production environment.
  22. 默认情况下,MariaDB提供了一个名为“测试”的数据库,任何人都可以访问。
  23. 这也只用于测试,在进入生产环境之前应该被删除。
  24. Reloading the privilege tables will ensure that all changes made so far
  25. will take effect immediately.
  26. 重新加载权限表将确保所有到目前为止所做的更改将立即生效。
  27. Reload privilege tables now? [Y/n] 现在重新加载权限表(是/否)
  28. All done! If you've completed all of the above steps, your MariaDBinstallation should now be secure.
  29. 全部完成!如果你已经完成了以上步骤,MariaDB安装现在应该安全。
  30. Thanks for using MariaDB!
  31. 感谢使用MariaDB!

编译安装MariaDB后所有配置操作

  1. [root@localhost ~]# cd /usr/local/mysql/
  2. [root@localhost mysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mysql/
  3. Installing MariaDB/MySQL system tables in '/data/mysql/' ...
  4. OK
  5. To start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your system
  6. PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
  7. To do so, start the server, then issue the following commands:
  8. './bin/mysqladmin' -u root password 'new-password'
  9. './bin/mysqladmin' -u root -h localhost.localdomain password 'new-password'
  10. Alternatively you can run:
  11. './bin/mysql_secure_installation'which will also give you the option of removing the testdatabases and anonymous user created by default. This is
  12. strongly recommended for production servers.
  13. See the MariaDB Knowledgebase at http://mariadb.com/kb or theMySQL manual for more instructions.
  14. You can start the MariaDB daemon with:cd '.' ; ./bin/mysqld_safe --datadir='/data/mysql/'
  15. You can test the MariaDB daemon with mysql-test-run.plcd './mysql-test' ; perl mysql-test-run.plPlease report any problems at http://mariadb.org/jiraThe latest information about MariaDB is available at http://mariadb.org/.You can find additional information about the MySQL part at:
  16. http://dev.mysql.comConsider joining MariaDB's strong and vibrant community:
  17. https://mariadb.org/get-involved/[root@localhost mysql]# cp support-files/my-large.cnf /etc/my.cnf
  18. [root@localhost mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
  19. [root@localhost mysql]# /etc/rc.d/init.d/mysqld start
  20. Reloading systemd: [ OK ]
  21. Starting mysqld (via systemctl): [ OK ]
  22. [root@localhost mysql]# touch /etc/profile.d/mysql.sh[root@localhost mysql]# echo 'export PATH=$PATH:/usr/local/mysql/bin/' > /etc/profile.d/mysql.sh [root@localhost mysql]# chmod 0777 /etc/profile.d/mysql.sh [root@localhost mysql]# source /etc/profile.d/mysql.sh [root@localhost mysql]# mysql
  23. Welcome to the MariaDB monitor. Commands end with ; or \g.
  24. Your MariaDB connection id is 10
  25. Server version: 10.2.6-MariaDB-log Source distributionCopyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  26. MariaDB [(none)]
点赞 ( 1 )

0 条评论

发表评论

人生在世,错别字在所难免,无需纠正。

插入图片
s
返回顶部