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
默认安装后的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 ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, 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): <–第一次运行因为用户root为空密码状态所以直接回车即可
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] <– 是否设置root用户密码,默认为“y”直接回车即可。
New password: <– 设置root用户的密码,密码不显示直接输入后回车即可。
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] <– 是否删除匿名用户,生产环境建议删除,默认为“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] <–是否禁止root远程登录,根据自己的需求选择;禁止的话默认为“y”直接回车即可。
... 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] <– 是否删除test数据库,生产环境建议删除,默认为“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!
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Cleaning up...
------------------------------------------------------------------------------------------------------------------------------------------
发表评论