CentOS6源码安装MySQL

本文详细介绍了如何在Linux环境下编译安装MySQL5.6,包括安装依赖、新建用户组、下载源码、配置编译选项、编译安装、初始化数据库、设置root用户密码和远程访问权限。特别提到了FEDERATED存储引擎的启用方法,以及在编译时必须指定该引擎以避免后期安装问题。
摘要由CSDN通过智能技术生成

安装编译源码所需工具和库(重要)

yum install gcc gcc-c++ ncurses-devel perl cmake bison

新建用户组及用户

groupadd mysql 

useradd -r -g mysql mysql  

新建安装目录

mkdir -p /usr/local/mysql 

mkdir -p /usr/local/mysql/data

下载MySQL源码

wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.26.tar.gz

解压缩命令

tar -zxvf mysql-5.6.26.tar.gz

使用cmake设置源码编译配置脚本

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_TCP_PORT=3306 -DENABLE_DOWNLOADS=1

ps: -DWITH_FEDERATED_STORAGE_ENGINE=1 跨服务器查询会用到,  如果编译的时候未指定FEDERATED引擎, 后期通过INSTALL PLUGIN的方式安装会出现问题

SQL>install plugin federated soname 'ha_federated.so';
ERROR 1126 (HY000): Can't open shared library '/usr/local/mysql/lib/mysql/plugin/ha_federated.so' (errno: 2 undefined symbol: dynstr_append_mem)

这是MySQL的bug, 只能通过编译源码重新安装解决, 项目难免会涉及到跨库操作, 所以此处在编译时手工指定FEDERATED引擎

编译源码

make

安装

make install

修改安装目录及数据库目录用户组及所有者

cd /usr/local/mysql
chown -R mysql:mysql .

cd /usr/local/mysql/data
chown -R mysql:mysql .

初始化MySQL数据库

cd /usr/local/mysql
/usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data/

复制配置文件

cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf 

修改默认字符集, 在my.cnf  文件 [mysqld] 标签下添加

vim /usr/local/mysql/my.cnf
character-set-server=utf8

创建mysqld系统服务

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

启动mysqld服务(CentOS 6 的命令)

service mysqld start

添加mysql系统命令, 编辑/etc/profile  , 追加以下内容 

PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH  
export PATH

使配置立即生效

source /etc/profile

进入控制台

复制代码

[root@localhost etc]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.26 Source distribution

Copyright (c) 2000, 2015, 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>

复制代码

设置root用户密码和远程访问权限

复制代码

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, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
Query OK, 0 rows affected (0.00 sec)

复制代码

finished

补充:

查看数据库是否支持FEDERATED引擎

复制代码

mysql> show engines;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                        | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                             | NO           | NO   | NO         |
| CSV                | YES     | CSV storage engine                                             | NO           | NO   | NO         |
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables      | NO           | NO   | NO         |
| BLACKHOLE          | YES     | /dev/null storage engine (anything you write to it disappears) | NO           | NO   | NO         |
| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                          | NO           | NO   | NO         |
| MyISAM             | YES     | MyISAM storage engine                                          | NO           | NO   | NO         |
| ARCHIVE            | YES     | Archive storage engine                                         | NO           | NO   | NO         |
| InnoDB             | DEFAULT | Supports transactions, row-level locking, and foreign keys     | YES          | YES  | YES        |
| FEDERATED          | NO      | Federated MySQL storage engine                                 | NULL         | NULL | NULL       |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
9 rows in set (0.00 sec)

复制代码

解决方法:

编辑 my.cnf 文件追加

federated 

仅此一条, 重启mysqld服务, 再看一下

复制代码

mysql> show engines;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                        | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                             | NO           | NO   | NO         |
| CSV                | YES     | CSV storage engine                                             | NO           | NO   | NO         |
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables      | NO           | NO   | NO         |
| BLACKHOLE          | YES     | /dev/null storage engine (anything you write to it disappears) | NO           | NO   | NO         |
| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                          | NO           | NO   | NO         |
| MyISAM             | YES     | MyISAM storage engine                                          | NO           | NO   | NO         |
| ARCHIVE            | YES     | Archive storage engine                                         | NO           | NO   | NO         |
| InnoDB             | DEFAULT | Supports transactions, row-level locking, and foreign keys     | YES          | YES  | YES        |
| FEDERATED          | YES     | Federated MySQL storage engine                                 | NO           | NO   | NO         |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
9 rows in set (0.00 sec)

复制代码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值