centos mysql 5.6.36_CentOS 7.2 编译安装 MySQL 5.6.36

73918f1420572269caa94cf16efbfc2b.png

环境说明:

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服务脚本并赋予执行权限

[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环境变量并重载环境变量[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[root@izuf6in4w20dqvk2nrs45kz mysql-5.6.36]# chkconfig --list mysqld

14、启动MySQL服务

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

15、登录MySQL,此时登录密码为空,直接就可以登录进去。[root@izuf6in4w20dqvk2nrs45kz mysql-5.6.36]# mysql

a7fa68707e8cb295f1a3921a02b56f57.png

初始化:

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

[root@izuf6in4w20dqvk2nrs45kz bin]# mysql_secure_installation

[root@izuf6in4w20dqvk2nrs45kz bin]# mysql_secure_installation

NOTE:RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALLMySQL

SERVERS IN PRODUCTION USE!PLEASE READ EACH STEP CAREFULLY!

Inorder to logintoMySQLto secure it,we'll need the current

password for the root user.  If you've just installedMySQL,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 MySQL

root user without the proper authorisation.

Set root password? [Y/n]

New password:

Re-enter new password:

Password updated successfully!

Reloading privilege tables..

... Success!

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

to log into MySQL 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]

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

... skipping.

By default, MySQL 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]

- 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]

... Success!

All done!  If you've completed all of the above steps,yourMySQL

installation should now be secure.

ThanksforusingMySQL!

Cleaningup...

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值