CentOS 7.2 编译安装 MySQL 5.6.36

                                                                                 

环境说明:


1、系统:CentOS最小化安装;升级软件补丁,内核和系统版本不升级;关闭SELinux和防火墙。


2、软件:安装包统一放置在/usr/src目录下,安装位置统一在/usr/local目录下。

开始安装:


1、CentOS7默认安装了MariaDB数据库,首先将卸载掉。

[root@localhost ~]# rpm -qa |grep maridb 


[root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64


2、YUM安装依赖包及所需的编译工具(cmake)

root@localhost ~]# yum install -y make gcc-c++ cmake bison-devel ncurses-devel autoconf


3、创建MySQL用户和组(用户属性为禁止登录及不创建家目录)


[root@localhost ~]# useradd -s /sbin/nologin -M mysql


4、进入软件包存放目录解压安装包并进入解压后的软件目录内

[root@localhost~]# cd /usr/src/

 root@localhost  src]# cd mysql-5.6.36


5、在安装包目录内,编译MySQL软件。


cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6.36 -DMYSQL_DATADIR=/usr/local/mysql-5.6.36/data -DSYSCONFDIR=/etc -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DWITH_READLINE=1 -DWITH_EMBEDDED_SERVER=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci


6、开始编译安装MySQL软件


root@localhost mysql-5.6.36]# make && make install


7、创建软链接


root@localhost mysql-5.6.36]# ln -s /usr/local/mysql-5.6.36/ /usr/local/mysql


8、设置MySQL目录属主和属组


root@localhost mysql-5.6.36]# chown -R mysql.mysql /usr/local/mysql/


9、拷贝MySQL配置文件;如果有提示(cp: overwrite `/etc/my.cnf’?)按“y”确认。

[root@localhost mysql-5.6.36]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf


10、初始化MySQL软件,指明安装目录、数据库存放位置及授权给mysql用户。PS:看到两个OK就代表没问题[

root@localhost mysql-5.6.36]# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql


11、拷贝MySQL服务脚本并赋予执行权限


  1. [root@localhost mysql-5.6.36]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld && chmod +x /etc/init.d/mysqld



12、配置MySQL环境变量并重载环境变量

  1. [root@local mysql-5.6.36]# echo 'export PATH=/usr/local/mysql/bin:$PATH' >>/etc/profile && source /etc/profile



13、将MySQL启动服务加入到系统服务并检查

[       root@izuf6in4w20dqvk2nrs45kz mysql-5.6.36]# chkconfig --add mysqld

  1. [root@izuf6in4w20dqvk2nrs45kz mysql-5.6.36]# chkconfig --list mysqld

14、启动MySQL服务

[root@localhost  mysql-5.6.36]# systemctl start mysqld



15、登录MySQL,此时登录密码为空,直接就可以登录进去。

  1. [root@izuf6in4w20dqvk2nrs45kz mysql-5.6.36]# mysql


image.png

初始化:


        默认安装后的MySQL用户root为空密码状态,存在匿名用户,存在测试数据库;利用/usr/local/mysql/bin目录下的mysql_secure_installation安全配置向导文件来初始化数据库


  1. [root@izuf6in4w20dqvk2nrs45kz bin]# mysql_secure_installation



  1. [root@izuf6in4w20dqvk2nrs45kz bin]# mysql_secure_installation

  2.  

  3.  

  4.  

  5. NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL

  6.      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

  7.  

  8. In order to log into MySQL to secure it, we'll need the current

  9. password for the root user.  If you've just installed MySQL, and

  10. you haven't set the root password yet, the password will be blank,

  11. so you should just press enter here.

  12.  

  13. Enter current password for root (enter for none): <–第一次运行因为用户root为空密码状态所以直接回车即可

  14. OK, successfully used password, moving on...

  15.  

  16. Setting the root password ensures that nobody can log into the MySQL

  17. root user without the proper authorisation.

  18.  

  19. Set root password? [Y/n] <– 是否设置root用户密码,默认为“y”直接回车即可。

  20. New password: <– 设置root用户的密码,密码不显示直接输入后回车即可。

  21. Re-enter new password: <– 再输入一次你设置的密码回车即可

  22. Password updated successfully!

  23. Reloading privilege tables..

  24. ... Success!

  25.  

  26.  

  27. By default, a MySQL installation has an anonymous user, allowing anyone

  28. to log into MySQL without having to have a user account created for

  29. them.  This is intended only for testing, and to make the installation

  30. go a bit smoother.  You should remove them before moving into a

  31. production environment.

  32.  

  33. Remove anonymous users? [Y/n] <– 是否删除匿名用户,生产环境建议删除,默认为“y”直接回车即可。

  34. ... Success!

  35.  

  36. Normally, root should only be allowed to connect from 'localhost'.  This

  37. ensures that someone cannot guess at the root password from the network.

  38.  

  39. Disallow root login remotely? [Y/n] <–是否禁止root远程登录,根据自己的需求选择;禁止的话默认为“y”直接回车即可。

  40. ... skipping.

  41.  

  42. By default, MySQL comes with a database named 'test' that anyone can

  43. access.  This is also intended only for testing, and should be removed

  44. before moving into a production environment.

  45.  

  46. Remove test database and access to it? [Y/n] <– 是否删除test数据库,生产环境建议删除,默认为“y”直接回车即可。

  47. - Dropping test database...

  48. ... Success!

  49. - Removing privileges on test database...

  50. ... Success!

  51.  

  52. Reloading the privilege tables will ensure that all changes made so far

  53. will take effect immediately.

  54.  

  55. Reload privilege tables now? [Y/n] <– 是否重新加载权限表,默认为“y”直接回车即可。

  56. ... Success!

  57.  

  58.  

  59.  

  60.  

  61. All done!  If you've completed all of the above steps, your MySQL

  62. installation should now be secure.

  63.  

  64. Thanks for using MySQL!

  65.  

  66.  

  67. Cleaning up...


------------------------------------------------------------------------------------------------------------------------------------------


作者头像
南宫俊逸创始人

君子好学,自强不息~

上一篇:CentOS7.2编译安装Nginx1.12.2
下一篇:CentOS 7.2编译安装PHP5.6.36

发表评论

阿里云2021年 618 年中钜惠活动