Home Database Mysql Tutorial Linux CentOS6.6下编译安装MySQL 5.6.16 详细教程(亲测成功)

Linux CentOS6.6下编译安装MySQL 5.6.16 详细教程(亲测成功)

Jun 07, 2016 pm 02:50 PM
centos6.6 linux mysql Install compile

一、编译安装MySQL前的准备工作 安装编译源码所需的工具和库 [sql] view plain copy yuminstallgccgcc-cncurses-develperl 安装cmake 官方:http://www.cmake.org下载源码并编译安装 csdn下载地址:http://download.csdn.net/detail/chun8416/9514242 [sql]

一、编译安装MySQL前的准备工作

安装编译源码所需的工具和库

[sql] view plain copy  在CODE上查看代码片派生到我的代码片
  1. yum install gcc gcc-c++ ncurses-devel perl  

安装cmake

官方:http://www.cmake.org下载源码并编译安装

csdn下载地址:http://download.csdn.net/detail/chun8416/9514242

[sql] view plain copy  在CODE上查看代码片派生到我的代码片
  1. wget http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz   
  2. tar -xzvf cmake-2.8.10.2.tar.gz   
  3. cd cmake-2.8.10.2   
  4. ./bootstrap ; make ; make install   
  5. cd ~  

二、设置MySQL用户和组

新增MySQL用户组

[sql] view plain copy  在CODE上查看代码片派生到我的代码片
  1. groupadd mysql  
新增mysql用户 [sql] view plain copy  在CODE上查看代码片派生到我的代码片
  1. useradd -r -g mysql mysql  

三、新建MySQL所需要的目录

新建mysql安装目录

[sql] view plain copy  在CODE上查看代码片派生到我的代码片
  1. mkdir -p /usr/local/mysql  
新建mysql数据库数据文件目录 [sql] view plain copy  在CODE上查看代码片派生到我的代码片
  1. mkdir -p /data/mysqldb  

四、下载MySQL源码包并解压

从http://dev.mysql.com/downloads/mysql/直接下载源码,解压mysql-5.6.16.tar.gz(http://www.quseqi.com/这个网站就是用的5.6.16版本)

csdn下载地址:http://download.csdn.net/detail/chun8416/9514255

[sql] view plain copy  在CODE上查看代码片派生到我的代码片
  1. wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.16.tar.gz
  2. tar -zxv -f mysql-5.6.16.tar.gz  
  3. cd mysql-5.6.16  


五、编译安装MySQL

从mysql5.5起,mysql源码安装开始使用cmake了,设置源码编译配置脚本。

设置编译参数

[sql] view plain copy  在CODE上查看代码片派生到我的代码片
  1. cmake \   
  2. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \   
  3. -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \   
  4. -DDEFAULT_CHARSET=utf8 \   
  5. -DDEFAULT_COLLATION=utf8_general_ci \   
  6. -DWITH_INNOBASE_STORAGE_ENGINE=1 \   
  7. -DWITH_ARCHIVE_STORAGE_ENGINE=1 \   
  8. -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \   
  9. -DMYSQL_DATADIR=/data/mysqldb \   
  10. -DMYSQL_TCP_PORT=3306 \   
  11. -DENABLE_DOWNLOADS=1  

-DCMAKE_INSTALL_PREFIX=dir_name 设置mysql安装目录
-DMYSQL_UNIX_ADDR=file_name 设置监听套接字路径,这必须是一个绝对路径名。默认为/tmp/mysql.sock
-DDEFAULT_CHARSET=charset_name 设置服务器的字符集。
缺省情况下,MySQL使用latin1的(CP1252西欧)字符集。cmake/character_sets.cmake文件包含允许的字符集名称列表。
-DDEFAULT_COLLATION=collation_name 设置服务器的排序规则。
-DWITH_INNOBASE_STORAGE_ENGINE=1 
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1
存储引擎选项:

MyISAM,MERGE,MEMORY,和CSV引擎是默认编译到服务器中,并不需要明确地安装。

静态编译一个存储引擎到服务器,使用-DWITH_engine_STORAGE_ENGINE= 1

可用的存储引擎值有:ARCHIVE, BLACKHOLE, EXAMPLE, FEDERATED, INNOBASE (InnoDB), PARTITION (partitioning support), 和PERFSCHEMA (Performance Schema)
-DMYSQL_DATADIR=dir_name 设置mysql数据库文件目录
-DMYSQL_TCP_PORT=port_num 设置mysql服务器监听端口,默认为3306
-DENABLE_DOWNLOADS=bool 是否要下载可选的文件。例如,启用此选项(设置为1),cmake将下载谷歌所使用的测试套件运行单元测试。

























注:重新运行配置,需要删除CMakeCache.txt文件

[sql] view plain copy  在CODE上查看代码片派生到我的代码片
  1. rm CMakeCache.txt  
编译源码

[sql] view plain copy  在CODE上查看代码片派生到我的代码片
  1. make  
安装

[sql] view plain copy  在CODE上查看代码片派生到我的代码片
  1. make install  

六、修改mysql目录所有者和组

修改mysql安装目录

[sql] view plain copy  在CODE上查看代码片派生到我的代码片
  1. cd /usr/local/mysql   
  2. chown -R mysql:mysql .  
修改mysql数据库文件目录
[sql] view plain copy  在CODE上查看代码片派生到我的代码片
  1. cd /data/mysqldb  
  2. chown -R mysql:mysql .  

七、初始化mysql数据库

[sql] view plain copy  在CODE上查看代码片派生到我的代码片
  1. cd /usr/local/mysql   
  2. scripts/mysql_install_db --user=mysql --datadir=/data/mysqldb  

八、复制mysql服务启动配置文件

[sql] view plain copy  在CODE上查看代码片派生到我的代码片
  1. cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf  
注:如果/etc/my.cnf文件存在,则覆盖。

九、复制mysql服务启动脚本及加入PATH路径

[sql] view plain copy  在CODE上查看代码片派生到我的代码片
  1. cp support-files/mysql.server /etc/init.d/mysqld   
  2.   
  3. vim /etc/profile   
  4.   
  5.       PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH  
  6.   
  7.       export PATH  
  8.   
  9. source /etc/profile    

十、启动mysql服务并加入开机自启动(可选这个步骤,以后可以自己启动的)

service mysqld start 
chkconfig --level 35 mysqld on

十一、检查mysql服务是否启动

[sql] view plain copy  在CODE上查看代码片派生到我的代码片
  1. netstat -tulnp | grep 3306   
  2. mysql -u root -p   
密码为空,如果能登陆上,则安装成功。

十二、修改MySQL用户root的密码

[sql] view plain copy  在CODE上查看代码片派生到我的代码片
  1. mysqladmin -u root password '123456'   
注:也可运行安全设置脚本,修改MySQL用户root的密码,同时可禁止root远程连接,移除test数据库和匿名用户。
[sql] view plain copy  在CODE上查看代码片派生到我的代码片
  1. /usr/local/mysql/bin/mysql_secure_installation  

十三、可能会出现的错误

[sql] view plain copy  在CODE上查看代码片派生到我的代码片
  1. 问题:   
  2. Starting MySQL..The server quit without updating PID file ([FAILED]/mysql/Server03.mylinux.com.pid).   
  3. 解决:   
  4. 修改/etc/my.cnf 中datadir,指向正确的mysql数据库文件目录  

[sql] view plain copy  在CODE上查看代码片派生到我的代码片
  1. 问题:   
  2. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)   
  3. 解决:   
  4. 新建一个链接或在mysql中加入-S参数,直接指出mysql.sock位置。   
  5. ln -s /usr/local/mysql/data/mysql.sock /tmp/mysql.sock   
  6.   
  7. /usr/local/mysql/bin/mysql -u root -S /usr/local/mysql/data/mysql.sock  

[sql] view plain copy  在CODE上查看代码片派生到我的代码片
  1. MySQL问题解决:-bash:mysql:command not found  
  2. 因为mysql命令的路径在/usr/local/mysql/bin下面,所以你直接使用mysql命令时,  
  3. 系统在/usr/bin下面查此命令,所以找不到了   
  4.    解决办法是:  
  5.  ln -s /usr/local/mysql/bin/mysql /usr/bin 做个链接即可  
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to open phpmyadmin How to open phpmyadmin Apr 10, 2025 pm 10:51 PM

You can open phpMyAdmin through the following steps: 1. Log in to the website control panel; 2. Find and click the phpMyAdmin icon; 3. Enter MySQL credentials; 4. Click "Login".

phpmyadmin connection mysql phpmyadmin connection mysql Apr 10, 2025 pm 10:57 PM

How to connect to MySQL using phpMyAdmin? The URL to access phpMyAdmin is usually http://localhost/phpmyadmin or http://[your server IP address]/phpmyadmin. Enter your MySQL username and password. Select the database you want to connect to. Click the "Connection" button to establish a connection.

How to view sql database error How to view sql database error Apr 10, 2025 pm 12:09 PM

The methods for viewing SQL database errors are: 1. View error messages directly; 2. Use SHOW ERRORS and SHOW WARNINGS commands; 3. Access the error log; 4. Use error codes to find the cause of the error; 5. Check the database connection and query syntax; 6. Use debugging tools.

How to start the server with redis How to start the server with redis Apr 10, 2025 pm 08:12 PM

The steps to start a Redis server include: Install Redis according to the operating system. Start the Redis service via redis-server (Linux/macOS) or redis-server.exe (Windows). Use the redis-cli ping (Linux/macOS) or redis-cli.exe ping (Windows) command to check the service status. Use a Redis client, such as redis-cli, Python, or Node.js, to access the server.

phpMyAdmin comprehensive use guide phpMyAdmin comprehensive use guide Apr 10, 2025 pm 10:42 PM

phpMyAdmin is not just a database management tool, it can give you a deep understanding of MySQL and improve programming skills. Core functions include CRUD and SQL query execution, and it is crucial to understand the principles of SQL statements. Advanced tips include exporting/importing data and permission management, requiring a deep security understanding. Potential issues include SQL injection, and the solution is parameterized queries and backups. Performance optimization involves SQL statement optimization and index usage. Best practices emphasize code specifications, security practices, and regular backups.

Summary of phpmyadmin vulnerabilities Summary of phpmyadmin vulnerabilities Apr 10, 2025 pm 10:24 PM

The key to PHPMyAdmin security defense strategy is: 1. Use the latest version of PHPMyAdmin and regularly update PHP and MySQL; 2. Strictly control access rights, use .htaccess or web server access control; 3. Enable strong password and two-factor authentication; 4. Back up the database regularly; 5. Carefully check the configuration files to avoid exposing sensitive information; 6. Use Web Application Firewall (WAF); 7. Carry out security audits. These measures can effectively reduce the security risks caused by PHPMyAdmin due to improper configuration, over-old version or environmental security risks, and ensure the security of the database.

How to use single threaded redis How to use single threaded redis Apr 10, 2025 pm 07:12 PM

Redis uses a single threaded architecture to provide high performance, simplicity, and consistency. It utilizes I/O multiplexing, event loops, non-blocking I/O, and shared memory to improve concurrency, but with limitations of concurrency limitations, single point of failure, and unsuitable for write-intensive workloads.

The 5 Pillars of Linux: Understanding Their Roles The 5 Pillars of Linux: Understanding Their Roles Apr 11, 2025 am 12:07 AM

The five pillars of the Linux system are: 1. Kernel, 2. System library, 3. Shell, 4. File system, 5. System tools. The kernel manages hardware resources and provides basic services; the system library provides precompiled functions for applications; the shell is the interface for users to interact with the system; the file system organizes and stores data; and system tools are used for system management and maintenance.

See all articles