search
HomeDatabaseMysql TutorialMySQL 5.5源码安装

MySQL 5.5源码安装

Jun 07, 2016 pm 03:18 PM
dbamysqlInstallSource code

MySQL 5.5的安装方法和5.1略有 不同,主要区别在配置环境,MySQL 5.1的安装方法,参考搭建LAMP环境(源码方式)。本文讲解怎样在RedHat 6.1系统上安装MySQL 5.5. 首先,我们要准备MySQL,至于在什么地方下载,想必不用多说,这个可难不倒聪明的小伙伴们。本文

MySQL 5.5的安装方法和5.1略有 不同,主要区别在配置环境,MySQL 5.1的安装方法,参考搭建LAMP环境(源码方式)。本文讲解怎样在RedHat 6.1系统上安装MySQL 5.5.


首先,我们要准备MySQL,至于在什么地方下载,想必不用多说,这个可难不倒聪明的小伙伴们。本文使用的MySQL版本是5.5.29,假设读者已经把该版本或者5.5的其他版本准备好了,下面正式讲解怎样安装MySQL 5.5。本文的操作均在虚拟机下完成。

第一步,真实机拷贝MySQL 5.5源码包到虚拟机下

[root@serv01 ~]# yum install /usr/bin/scp -y
[root@larrywen ule-mysql]# scpmysql-5.5.29.tar.gz 192.168.1.11:/opt
root@192.168.1.11's password:
mysql-5.5.29.tar.gz                                                                                100%   24MB  23.7MB/s  00:00

第二步,对源码进行编译需要make等命令,所以我们安装开发工具包

[root@serv01 ~]# yum grouplist | grep Devel
  Additional Development
  Desktop Platform Development
  Development tools
  Server Platform Development
[root@serv01 ~]# yum groupinstall"Development tools" -y

 

第三步,解压源码包到/usr/src目录,/usr/src是建议命令

[root@serv01 opt]# tar -xvf mysql-5.5.29.tar.gz -C /usr/src/

第四步,进入MySQL的解压目录

<span>
[root@serv01 opt]# cd /usr/src/mysql-5.5.29/
</span><span>#安装帮助文档(可以参考这个文件进行安装)</span><span>
[root@serv01 mysql-5.5.29]# vim INSTALL-SOURCE
shell> tar zxvf mysql-VERSION.tar.gz
shell> cd mysql-VERSION
shell> cmake .
shell> make
shell> make install
# End of source-build specific instructions
# Postinstallation setup
shell> cd /usr/local/mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db--user=mysql
shell> chown -R root .
shell> chown -R mysql data
# Next command is optional
shell> cp support-files/my-medium.cnf/etc/my.cnf
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server/etc/init.d/mysql.server
</span>

 

第五步,因为配置环境需要使用到cmake,且MySQL依赖ncurses-devel包,所以我们安装cmake和ncurses-devel

[root@serv01 mysql-5.5.29]# yum install cmake-y
[root@serv01 mysql-5.5.29]# yum install ncurses-devel -y

 

第六步,关键步骤,这一步也是和MySQL 5.1的不同之处,使用cmake命令配置环境,如下

<span>[root@serv01 mysql-5.5.29]# cmake .  \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DWITH_INNOBASE_STORAGE_ENGINE=1  \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DDEFAULT_CHARSET=utf8  \
-DDEFAULT_COLLATION=utf8_general_ci  \
-DWITH_EXTRA_CHARSETS=all \
-DMYSQL_TCP_PORT=3306  \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock  \
-DMYSQL_DATADIR=/usr/local/mysql/data

</span><span><strong>解释:</strong></span><span>
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql:MySQL安装目录,推荐安装到此目录
-DWITH_INNOBASE_STORAGE_ENGINE=1:安装InnoDB存储引擎
-DWITH_MYISAM_STORAGE_ENGINE=1:安装MyISAM存储引擎
-DWITH_MEMORY_STORAGE_ENGINE=1:安装内存存储引擎
-DDEFAULT_CHARSET=utf8:默认编码设置成utf8
-DDEFAULT_COLLATION=utf8_general_ci:默然校验规则是utf8_general_ci
-DWITH_EXTRA_CHARSETS=all:支持其他所有的编码
-DMYSQL_TCP_PORT=3306:MySQL端口指定为3306
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock:指定SOCK文件路径
-DMYSQL_DATADIR=/usr/local/mysql/data:MySQL数据目录
</span>

第七步,编译安装

<span>[root@serv01 mysql-5.5.29]# make && make install

</span><span>#确定安装目录存在</span><span>
[root@serv01 mysql-5.5.29]# ls/usr/local/mysql/
bin COPYING  data  docs include  INSTALL-BINARY  lib man  mysql-test  README scripts  share  sql-bench support-files
</span>

第八步,添加mysql组和用户

[root@serv01 opt]# groupadd -g 500 mysql
[root@serv01 opt]# useradd -u 500 -g 500 -r -M -s /sbin/nologin mysql 

第九步,拷贝配置文件和启动脚本,并修改启动脚本的执行权限

[root@serv01 mysql-5.5.29]# cpsupport-files/my-medium.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf'? y
[root@serv01 mysql-5.5.29]# cpsupport-files/mysql.server /etc/init.d/mysqld
[root@serv01 mysql-5.5.29]# chmod a+x/etc/init.d/mysqld
[root@serv01 mysql-5.5.29]# ls /usr/local/mysql/data/
mysql test

第十步,改变mysql目录的拥有者和所属组,并修改my.cnf文件,添加data目录

[root@serv01 mysql-5.5.29]# chown mysql.mysql/usr/local/mysql/ -R
[root@serv01 mysql-5.5.29]# vim /etc/my.cnf
[root@serv01 mysql-5.5.29]# cat /etc/my.cnf |grep datadir
datadir         =/usr/local/mysql/data

第十一步,修改mysql_install_db的权限,使其可执行,并进行初始化操作

[root@serv01 mysql-5.5.29]# chmod a+xscripts/mysql_install_db
[root@serv01 mysql-5.5.29]#./scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data/--basedir=/usr/local/mysql/
WARNING: The host 'serv01.host.com' could notbe looked up with resolveip.
This probably means that your libc librariesare not 100 % compatible
with this binary MySQL version. The MySQLdaemon, mysqld, should work
normally with the exception that host nameresolving will not work.
This means that you should use IP addressesinstead of hostnames
when specifying MySQL privileges !
Installing MySQL system tables...
OK
Filling help tables...
OK
 
To start mysqld at boot time you have to copy
support-files/mysql.server to the right placefor your system
 
PLEASE REMEMBER TO SET A PASSWORD FOR THEMySQL root USER !
To do so, start the server, then issue thefollowing commands:
 
/usr/local/mysql//bin/mysqladmin -u rootpassword 'new-password'
/usr/local/mysql//bin/mysqladmin -u root -hserv01.host.com password 'new-password'
 
Alternatively you can run:
/usr/local/mysql//bin/mysql_secure_installation
 
which will also give you the option ofremoving the test
databases and anonymous user created bydefault.  This is
strongly recommended for production servers.
 
See the manual for more instructions.
 
You can start the MySQL daemon with:
cd /usr/local/mysql/ ;/usr/local/mysql//bin/mysqld_safe &
 
You can test the MySQL daemon withmysql-test-run.pl
cd /usr/local/mysql//mysql-test ; perlmysql-test-run.pl
 
Please report any problems with the/usr/local/mysql//scripts/mysqlbug script!

第十二步,启动MySQL,如果出现SUCCESS,恭喜您,MySQL启动成功;如果出错,不要着急,根据日志排查错误

<span>[root@serv01 mysql-5.5.29]#/etc/init.d/mysqld start
</span><span>Starting MySQL.. SUCCESS!</span><span>
[root@serv01 mysql-5.5.29]# ll/usr/local/mysql/data/ -d
drwxr-xr-x. 5 mysql mysql 4096 Sep  4 23:39 /usr/local/mysql/data/
</span>

第十三步,添加环境变量,并使其生效

[root@serv01 mysql-5.5.29]# vim~/.bash_profile
[root@serv01 mysql-5.5.29]# . !$
. ~/.bash_profile
[root@serv01 mysql-5.5.29]# cat ~/.bash_profile| grep PATH
PATH=/usr/local/mysql/bin/:$PATH:$HOME/bin
export PATH

第十四步,登录mysql,查看版本,如果出现版本号,则证明安装成功

<span>[root@serv01 mysql-5.5.29]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.29-log Sourcedistribution
 
Copyright (c) 2000, 2012, Oracle and/or itsaffiliates. All rights reserved.
 
Oracle is a registered trademark of OracleCorporation and/or its
affiliates. Other names may be trademarks oftheir respective
owners.
 
Type 'help;' or '\h' for help. Type '\c' toclear the current input statement.
 
mysql> select version();
+------------+
| version() |
+------------+
| </span><span>5.5.29-log</span><span> |
+------------+
1 row in set (0.00 sec)
 
mysql> exit
Bye

</span>
如果需要安装多个MySQL,需要修改端口,修改sock文件
[root@serv01 mysql-5.5.29]# cat /etc/my.cnf |grep -e sock -e port
port              =3306
socket           =/tmp/mysql.sock

<span><span>我的邮箱</span></span><span>:</span>wgbno27@163.com <span> <span>新浪微博</span></span><span>:</span>@Wentasy27
  <span>微信公众平台</span>:JustOracle(微信号:justoracle)
  <span>数据库技术交流群</span>:336882565(加群时验证 From CSDN XXX)
  <span><strong>All is well</strong></span>
  <span><strong>2013年10月20日</strong></span>
  <span><strong>By Larry Wen</strong></span>


MySQL 5.5源码安装 MySQL 5.5源码安装 MySQL 5.5源码安装
@Wentasy
Statement
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
MySQL's Role: Databases in Web ApplicationsMySQL's Role: Databases in Web ApplicationsApr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

MySQL: Building Your First DatabaseMySQL: Building Your First DatabaseApr 17, 2025 am 12:22 AM

The steps to build a MySQL database include: 1. Create a database and table, 2. Insert data, and 3. Conduct queries. First, use the CREATEDATABASE and CREATETABLE statements to create the database and table, then use the INSERTINTO statement to insert the data, and finally use the SELECT statement to query the data.

MySQL: A Beginner-Friendly Approach to Data StorageMySQL: A Beginner-Friendly Approach to Data StorageApr 17, 2025 am 12:21 AM

MySQL is suitable for beginners because it is easy to use and powerful. 1.MySQL is a relational database, and uses SQL for CRUD operations. 2. It is simple to install and requires the root user password to be configured. 3. Use INSERT, UPDATE, DELETE, and SELECT to perform data operations. 4. ORDERBY, WHERE and JOIN can be used for complex queries. 5. Debugging requires checking the syntax and use EXPLAIN to analyze the query. 6. Optimization suggestions include using indexes, choosing the right data type and good programming habits.

Is MySQL Beginner-Friendly? Assessing the Learning CurveIs MySQL Beginner-Friendly? Assessing the Learning CurveApr 17, 2025 am 12:19 AM

MySQL is suitable for beginners because: 1) easy to install and configure, 2) rich learning resources, 3) intuitive SQL syntax, 4) powerful tool support. Nevertheless, beginners need to overcome challenges such as database design, query optimization, security management, and data backup.

Is SQL a Programming Language? Clarifying the TerminologyIs SQL a Programming Language? Clarifying the TerminologyApr 17, 2025 am 12:17 AM

Yes,SQLisaprogramminglanguagespecializedfordatamanagement.1)It'sdeclarative,focusingonwhattoachieveratherthanhow.2)SQLisessentialforquerying,inserting,updating,anddeletingdatainrelationaldatabases.3)Whileuser-friendly,itrequiresoptimizationtoavoidper

Explain the ACID properties (Atomicity, Consistency, Isolation, Durability).Explain the ACID properties (Atomicity, Consistency, Isolation, Durability).Apr 16, 2025 am 12:20 AM

ACID attributes include atomicity, consistency, isolation and durability, and are the cornerstone of database design. 1. Atomicity ensures that the transaction is either completely successful or completely failed. 2. Consistency ensures that the database remains consistent before and after a transaction. 3. Isolation ensures that transactions do not interfere with each other. 4. Persistence ensures that data is permanently saved after transaction submission.

MySQL: Database Management System vs. Programming LanguageMySQL: Database Management System vs. Programming LanguageApr 16, 2025 am 12:19 AM

MySQL is not only a database management system (DBMS) but also closely related to programming languages. 1) As a DBMS, MySQL is used to store, organize and retrieve data, and optimizing indexes can improve query performance. 2) Combining SQL with programming languages, embedded in Python, using ORM tools such as SQLAlchemy can simplify operations. 3) Performance optimization includes indexing, querying, caching, library and table division and transaction management.

MySQL: Managing Data with SQL CommandsMySQL: Managing Data with SQL CommandsApr 16, 2025 am 12:19 AM

MySQL uses SQL commands to manage data. 1. Basic commands include SELECT, INSERT, UPDATE and DELETE. 2. Advanced usage involves JOIN, subquery and aggregate functions. 3. Common errors include syntax, logic and performance issues. 4. Optimization tips include using indexes, avoiding SELECT* and using LIMIT.

See all articles

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)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment