源码安装 与二进制(RPM)发行版本相比,如果我们选择了通过源代码进行安装,那么在安装过程中我们能够对MySQL 所做的调整将会更多更灵活一些。因为通过源代码编译我们可以: a) 针对自己的硬件平台选用合适的编译器来优化编译后的二进制代码; b) 根据不同的软件平台环境调整相关的编译参数; c) 针对我们特定应用场景选择需要什么组件不需要什么组件; d) 根据我们的所需要存储的数据内容选择只安装我们需要的字符集(utf-8); e) 同一台主机上面可以安装多个MySQL;
在源码安装给我们带来更大灵活性的同时,同样也给我们带来了可能引入的隐患: a) 对编译参数的不够了解造成编译参数使用不当可能使编译出来的二进制代码不够稳定; b) 对自己的应用环境把握失误而使用的优化参数可能反而使系统性能更差; c) 还有一个并不能称之为隐患的小问题就是源码编译安装将使安装部署过程更为复杂,所花费的时间更长;
4.启动mysqld服务 [root@mysql_source mysql]# mysqld_safe --defaults-file=/etc/my.cnf & # 这种启动方法我们不用,我们使用脚本的方式启动,也就是我们的第五步。 [1] 25705 2019-8-18T09:19:35.334751Z mysqld_safe Logging to '/usr/local/log/mysql_error.log'. 2019-8-18T09:19:35.379829Z mysqld_safe Starting mysqld daemon with databases from /usr/local/data
# 如果不小心执行了这一步启动,并且无法关闭掉,那么我们应该先去过滤初始密码 ,修改初始密码,然后使用 mysqladmin -uroot -p'密码' shutdown 进行关闭,在后面的使用中,我们就是用管理工具进行启动或关闭。 ##登录数据库并进行更改密码 [root@mysql_source mysql]# grep "password" /usr/local/log/mysql_error.log 2019-8-18T09:18:34.214401Z 1 [Note] A temporary password is generated for root@localhost: ejhszb2:m3wJ [root@mysql_source tmp]# mysql -uroot -p"ejhszb2:m3wJ" mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.24-log
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> alter user 'root'@'localhost' identified by "QianFeng@123";
5.配置mysqld服务的管理工具(便于启动) [root@mysql_source support-files]# cd /usr/local/mysql/support-files [root@mysql_source support-files]# cp mysql.server /etc/init.d/mysqld [root@mysql_source support-files]# chkconfig --add mysqld [root@mysql_source support-files]# chkconfig mysqld on
# 启动数据库 [root@mysql_source support-files]# service mysqld start #重启就是restart # 关闭就是stop