[root@docker-1etc]# cd /usr/local/

[root@docker-1src]# wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.48.tar.gz

#下载MySQL的源码包

[root@docker-1src]# tar xf mysql-5.6.48.tar.gz

#将下载的源码包解压到本地 

[root@docker-1src] ll

 #  total 31452

-drwxr-xr-x347161314154096Sep1611:38mysql-5.6.48

-rw-r--r--1root root32200158Jun223:54  mysql-5.6.48.tar.gz

 [root@docker-1mysql-5.6.48]# id mysql 

#检查系统是否存在mysql用户id: mysql: no such user 

#如果不存在则创建mysql用户

[root@docker-1mysql-5.6.48]# groupadd -g 550 mysql

 [root@docker-1mysql-5.6.48]# useradd -g mysql -u 550 mysql

[root@docker-1mysql-5.6.48]# id mysqluid=550(mysql) gid=550(mysql) groups=550(mysql) 

 

#安装编译前的依赖

 [root@docker-1mysql-5.6.48]# yum install cmake autoconf wget gcc-c++ gcc ncurses-devel -y

 [root@docker-1src]# cd mysql-5.6.48/ 

 

 

注意:默认字符集最好放前面 (-DDEFAULT_CHARSET=utf8),否则make 编译时容易报错error: ‘DDEFAULT_CHARSET’ was not declared in this scope:

 

 

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DMYSQL_DATADIR=/usr/local/mysql/data \

-DSYSCONFDIR=/usr/local/mysql/ \

-DDEFAULT_CHARSET=utf8 \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_engine_STORAGE_ENGINE=1 \

-DWITH_MEMORY_STORAGE_ENGINE=1 \

-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysqld.sock \

-DMYSQL_TCP_PORT=3306 \

-DENABLED_LOCAL_INFILE=1 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DEXTRA_CHARSETS=all \

-DDEFAULT_COLLATION=utf8_general_ci

 

 

执行完cmake之后、执行make和make install 整个过程时间较长、请稍等!

 编译参数详解 -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \          

#安装路径

-DMYSQL_DATADIR=/usr/local/mysql/data \                                        

#数据文件存放地

-DSYSCONFDIR=/etc \                                                                         

#配置文件my.cnf存放地

-DWITH_MYISAM_STORAGE_ENGINE=1 \                                        

#支持MyIASM引擎

-DWITH_INNOBASE_STORAGE_ENGINE=1 \                                   

#支持InnoDB引擎

-DWITH_MEMORY_STORAGE_ENGINE=1 \                                      

#支持Memory引擎

-DMYSQL_UNIX_ADDR=/var/run/mysql/mysqld.sock \                       

#连接数据库socket路径

-DMYSQL_TCP_PORT=3306 \                                                            

#数据库端口号

-DENABLED_LOCAL_INFILE=1 \                                                        

#允许从本地导入数据

-DWITH_PARTITION_STORAGE_ENGINE=1 \                                  

#安装支持数据库分区

-DEXTRA_CHARSETS=all \                                                                

#安装所有的字符集                                

-DDEFAULT_CHARSET=utf8 \                                                            

#默认字符

-DDEFAULT_COLLATION=utf8_general_ci

[root@docker-1local]# cd /usr/local/mysql

[root@docker-1mysql]# ll #编译后的文件

[root@localhost ~]# ll /usr/local/mysql/

total 240

drwxr-xr-x  2 root root  4096 Jul 25 18:37 bin

drwxr-xr-x  3 root root    18 Jul 25 18:36 data

drwxr-xr-x  2 root root    55 Jul 25 18:34 docs

drwxr-xr-x  3 root root  4096 Jul 25 18:34 include

drwxr-xr-x  3 root root    291 Jul 25 18:36 lib

-rw-r--r--  1 root root 219733 Mar  9 18:37 LICENSE

drwxr-xr-x  4 root root    30 Jul 25 18:35 man

drwxr-xr-x 10 root root  4096 Jul 25 18:39 mysql-test

-rw-r--r--  1 root root    587 Mar  9 18:37 README

drwxr-xr-x  2 root root    30 Jul 25 18:37 scripts

drwxr-xr-x 28 root root  4096 Jul 25 18:39 share

drwxr-xr-x  4 root root  4096 Jul 25 18:39 sql-bench

drwxr-xr-x  2 root root    136 Jul 25 18:39 support-files

[root@localhost ~]#

 

 

[root@localhost ~]# [root@docker-1mysql]# chown -R mysql.mysql  /usr/local/mysql

#对当前目录授权 数据库初始化 初始化之前需要修改my.cnf文件、内容如下:

  [root@localhost mysql]# more my.cnf

[mysql] socket=/usr/local/mysql/mysql.sock

default-character-set=utf8 [mysqld]

skip-grant-tables explicit_defaults_for_timestamp=true

skip-name-resolve

port=3306 socket=/usr/local/mysql/mysql.sock basedir=/usr/local/mysql

max_connections=200

default-storage-engine=INNODB

lower_case_table_names=1

max_allowed_packet=16M

log-error=/usr/local/mysql/mysql.log

pid-file=/usr/local/mysql/mysql.pid

如果初始化报错:FATAL ERROR: Could not find ./bin/my_print_defaults 则加上 --basedir=/usr/local/mysql 就可以了

 

[root@docker-1mysql]# 

./mysql_install_db --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql/ --no-defaults #开始初始化此时MySQL还是启动不了、还需要做些后续操作

 [root@docker-1mysql]# cp ./support-files/mysql.server /etc/init.d/mysql #拷贝启动文件

[root@docker-1mysql]# chmod +x /etc/init.d/mysql

[root@docker-1mysql]# /etc/init.d/mysql start

#启动报错了Starting MySQL.Logging to'/var/log/mysql/mysql.log'.17091612:28:00mysqld_safe Directory'/var/lib/mysql'forUNIX socketfiledon't exists.ERROR! The server quit without updating PIDfile(/var/run/mysql/mysql.pid). Starting MySQL.200725 18:59:31 mysqld_safe error: log-error set to '/usr/local/mysql/mysql.log', however file don't exists. Create writable for user 'mysql'. ERROR! The server quit without updating PID file (/usr/local/mysql/mysql.pid).

 

 

 

[root@docker-1mysql]# mkdir /usr/local/mysql   -p

[root@docker-1mysql]# chown -R mysql.mysql   /usr/local/mysql

[root@docker-1mysql]# chown -R mysql.mysql /usr/local/mysql

[root@docker-1mysql]# /etc/init.d/mysql start #再次启动Starting MySQL. SUCCESS! #成功

[root@docker-1mysql] #

[root@docker-1mysql]# ps aux|grep mysql #查看mysql进程

[root@localhost mysql-5.6.48]# /etc/init.d/mysql start Starting MySQL.200725 18:59:31 mysqld_safe error: log-error set to '/usr/local/mysql/mysql.log', however file don't exists. Create writable for user 'mysql'. ERROR! The server quit without updating PID file (/usr/local/mysql/mysql.pid). 启动失败 换种方式启动:

/usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/mysql.pid 设置 /usr/local/mysql/my.cnf

 

启动成功:

 

添加登录跳过输入密码

[mysqld] skip-grant-tables

 [root@localhost mysql]# /usr/local/mysql/bin/mysql -u root -p123456

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.48 Source distribution Copyright (c) 2000, 2020, 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> use mysql;

Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed

mysql> update user set password=password('123456') where user='root';

Query OK, 3 rows affected (0.00 sec) Rows matched: 3 Changed: 3 Warnings: 0

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec) 

授权:root用户

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> quit 

 

 

#注释掉 设置 /usr/local/mysql/my.cnf 

#添加登录跳过输入密码

[mysqld] #skip-grant-tables 可以直接执行

sed -i 's/skip-grant-tables/#skip-grant-tables/' /usr/local/mysql/my.cnf

可以直接登录了

[root@localhost mysql]# /usr/local/mysql/bin/mysql -u root -p123456

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.6.48 Source distribution Copyright (c) 2000, 2020, 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>