当前位置: 首页 > 工具软件 > xzs-mysql > 使用案例 >

Database-Mysql-源码编译安装Mysql

幸阳波
2023-12-01

官网下载mysql-5.7.24.tar.gz
官网–mysql community server–Looking for previous GA versions–选择源码–Generic Linux (Architecture Independent), Compressed TAR Archive
Includes Boost Headers

adson@adson-ThinkPad-T450:~/Downloads$ tar xzvf mysql-boost-5.7.24.tar.gz
adson@adson-ThinkPad-T450:~/Downloads/mysql-5.7.24$ ls
boost dbug libmysql rapid testclients
BUILD Docs libmysqld README unittest
client Doxyfile-perfschema libservices regex VERSION
cmake extra man scripts vio
CMakeLists.txt include mysql-test sql win
cmd-line-utils INSTALL mysys sql-common zlib
config.h.cmake libbinlogevents mysys_ssl storage
configure.cmake libbinlogstandalone packaging strings
COPYING libevent plugin support-files

adson@adson-ThinkPad-T450:~/Downloads/mysql-5.7.24$ mkdir debug //用来存放编译中间文件等,不会污染源码目录,想要清除时直接删除该文件夹
adson@adson-ThinkPad-T450:~/Downloads/mysql-5.7.24$ cd debug/

adson@adson-ThinkPad-T450:~/Downloads/mysql-5.7.24/debug$ sudo apt-get install bison
adson@adson-ThinkPad-T450:~/Downloads/mysql-5.7.24/debug$ sudo apt-get install zlib1g-dev
adson@adson-ThinkPad-T450:~/Downloads/mysql-5.7.24/debug$ sudo apt-get install libncurses5-dev

adson@。。debug$ cmake … -DBUILD_CONFIg=mysql_release
-DINSTALL_LAYOUT=STANDALONE
-DCMAKE_BUILD_TYPE=RelWithDebInfo
-DENABLE_DTRACE=OFF
-DWITH_EMBEDDED_SERVER=OFF
-DWITH_INNODB_MEMCACHED=ON
-DWITH_SSL=bundled
-DWITH_ZLIB=system
-DWITH_PAM=ON
-DCMAKE_INSTALL_PREFIX=/var/mysql/
-DINSTALL_PLUGINDIR="/var/mysql/lib/plugin"
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DWITH_EDITLINE=bundled
-DFEATURE_SET=community
-DCOMPILATION_COMMENT=“MySQL Server (GPL)”
-DWITH_DEBUG=OFF
-DWITH_BOOST=…/boost


– Configuring done
– Generating done
CMake Warning:
Manually-specified variables were not used by the project:
BUILD_CONFIg
WITH_PAM

adson@adson-ThinkPad-T450:~/Downloads/mysql-5.7.24/debug$ make -j 24 //设置24个线程进行编译
adson@adson-ThinkPad-T450:~/Downloads/mysql-5.7.24/debug$ sudo make install
adson@adson-ThinkPad-T450:~/Downloads/mysql-5.7.24/debug$ cd /var/mysql/
adson@adson-ThinkPad-T450:/var/mysql$ ls
bin COPYING-test include man README share
COPYING docs lib mysql-test README-test support-files

安装mysql库
adson@adson-ThinkPad-T450:/var/mysql$ sudo mkdir data_3306
adson@adson-ThinkPad-T450:/var/mysql$ sudo vi my.cnf
[mysqld]
port=3306
datadir=/var/mysql/data_3306
log_error=/var/mysql/data_3306/error.log
basedir=/var/mysql/
innodb_status_file=1 ##启用InnoDB的status file,便于管理员查看以及监控等

adson@adson-ThinkPad-T450:/var/mysql$ sudo groupadd mysql
adson@adson-ThinkPad-T450:/var/mysql$ sudo useradd -g mysql mysql

adson@adson-ThinkPad-T450:/var/mysql$ sudo chown -R mysql /var/mysql/data_3306/
adson@adson-ThinkPad-T450:/var/mysql/data_3306$ sudo /var/mysql/bin/mysqld --defaults-file=/var/mysql/my.cnf --initialize --user=mysql
在error日志可以看到2018-11-06T03:57:44.150388Z 1 [Note] A temporary password is generated for root@localhost: NFV_Bi2y%p!9

adson@adson-ThinkPad-T450:~$ sudo vi /etc/profile
PATH=/var/mysql/bin:/var/mysql/lib: P A T H d s o n @ a d s o n − T h i n k P a d − T 450 :   PATH dson@adson-ThinkPad-T450:~ PATHdson@adsonThinkPadT450:  source /etc/profile
adson@adson-ThinkPad-T450:~$ sudo cp /var/mysql/support-files/mysql.server /etc/init.d/mysqld
adson@adson-ThinkPad-T450:~$ sudo chmod +x /etc/init.d/mysqld
adson@adson-ThinkPad-T450:~$ update-rc.d mysqld defaults
adson@adson-ThinkPad-T450:~$ systemctl mysqld status

采用临时密码登录:
adson@adson-ThinkPad-T450:~$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.24

Copyright © 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> show variables like “%sock%”;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user ‘root’@‘localhost’ identified by ‘adson’;
Query OK, 0 rows affected (0.00 sec)

密码安全:
5.7提供了一种兼容模式,在初始化数据库时可使用参数–initialize-insecure,这样一来,其行为就与5.6版本之前的一样了。
这种方法给自动化运维带来了方便,但是背离了5.7这种处理方式的初衷,所以需要想清楚这个可能造成的不安全因素。

 类似资料: