mysql 5.5.48源码安装_MySQL 5.6.48源码编译安装

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

#下载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:54mysql-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/

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是在 CentOS 7 上编译安装 MySQL 5.6.50 的步骤: 1. 确保系统已安装必要的依赖库: ```shell yum -y install gcc gcc-c++ make cmake bison-devel ncurses-devel ``` 2. 下载 MySQL 5.6.50 源码包: ```shell wget https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.50.tar.gz ``` 3. 解压缩源码包: ```shell tar -zxvf mysql-5.6.50.tar.gz cd mysql-5.6.50 ``` 4. 配置编译选项: ```shell cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/usr/local/mysql/data \ -DSYSCONFDIR=/etc \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DWITH_SSL=system \ -DWITH_ZLIB=system \ -DWITH_LIBWRAP=0 \ -DWITH_EMBEDDED_SERVER=0 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_FEDERATED_STORAGE_ENGINE=1 \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DWITH_BOOST=../boost ``` 5. 编译安装: ```shell make && make install ``` 6. 添加 MySQL 用户和用户组: ```shell groupadd mysql useradd -r -g mysql -s /bin/false mysql ``` 7. 初始化 MySQL 数据库: ```shell cd /usr/local/mysql ./scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data/ ``` 8. 修改配置文件: ```shell cp support-files/my-default.cnf /etc/my.cnf vi /etc/my.cnf ``` 在 [mysqld] 段中添加以下内容: ```shell datadir=/usr/local/mysql/data socket=/usr/local/mysql/mysql.sock ``` 9. 启动 MySQL 服务: ```shell /usr/local/mysql/support-files/mysql.server start ``` 10. 设置开机自启动: ```shell cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql chmod +x /etc/init.d/mysql chkconfig mysql on ``` 11. 设置 MySQL 环境变量: ```shell echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile source /etc/profile ``` 现在,你已经成功地在 CentOS 7 上编译安装MySQL 5.6.50。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值