Home Database Mysql Tutorial Linux下MySQL 5.5.8 源码编译安装记录分享_MySQL

Linux下MySQL 5.5.8 源码编译安装记录分享_MySQL

Jun 01, 2016 pm 01:22 PM
linux Record

bitsCN.com

系统:Ubuntu 10.10
mysql源码文件:mysql-5.5.8.tar.gz
安装所需工具:cmake, GNU make, gcc, Perl, libncurses5-dev, bison(可选), chkconfig
注:
1.官方2010-11-18的源码有几处bug,在编译之前参照官方的说明,进行了手动修改。

官方说明链接:http://lists.mysql.com/commits/126782
2.官方5.5版本参考手册:http://dev.mysql.com/doc/
汗了一下,3392页的参考手册!
=>工具安装:
1. cmake
----没有自己编译安装cmake
----shell:~$ sudo apt-get install cmake
----版本:2.8.2
2. GNU make
----Ubuntu自带
----版本:3.81
3.GCC
----Ubuntu自带
----版本:4.4.5(官方文档:必须3.2以上)
4.Perl
----Ubuntu自带
----版本:5.10.1
5.libncurses5-dev (ncurses-devel)
----若差了这个包,在cmake的时候会报错。
----Debian/Ubuntu上的包名是libncurses5-dev,RedHat和其他版本对应的是ncurses-devel
----shell:~$ sudo apt-get install libncurses5-dev
----报错信息
------------------www.linuxidc.com---------------
-- MySQL 5.5.8
-- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:82 (MESSAGE):
Curses library not found. Please install appropriate package,

remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu , package name is libncurses5-dev ,
on RedHat and derivates it is ncurses-devel.
Call Stack (most recent call first):
cmake/readline.cmake:126 (FIND_CURSES)
cmake/readline.cmake:216 (MYSQL_USE_BUNDLED_LIBEDIT)
CMakeLists.txt:256 (MYSQL_CHECK_READLINE)

-- Configuring incomplete, errors occurred!
---------------------------------
6. bison
----shell:~$ sudo apt-get install bison
----可选。没有这个工具,在make的时候报出警告。
----警告记录:
---------------------------------

Warning: Bison executables not found in PATH
---------------------------------
7.chkconfig
----后面配置mysql服务自启动的时候需要。
----shell:~$ sudo apt-get install chkconfig
=>mysql安装:
1.解压源代码文件
----shell定位到源代码文件所在目录
----解压
shell:~$ tar zxvf mysql-5.5.8.tar.gz
2.cmake操作
----shell定位到解压出的源代码文件夹目录(文件夹:mysql-5.5.8)
----cmake执行:
---------------------------------
shell:~$ cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_DATADIR=/home/system_username/Programming/mysql/mysqldata
-DSYSCONFDIR=/etc
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_FEDERATED_STORAGE_ENGINE=1
-DWITH_PARTITION_STORAGE_ENGINE=1
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock
-DMYSQL_TCP_PORT=3306
-DENABLED_LOCAL_INFILE=1
-DEXTRA_CHARSETS=all
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8-general_ci
-DMYSQL_USER=mysql
注:没有换行。官方文档上,cmake 命令后面加个点不懂什么意思。在这里加上命令执行不了
---------------------------------
源代码配置选项说明:
//mysql安装的主目录,5.5.8版本默认为/usr/local/mysql,所以可以不添加
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql

//mysql数据保存的路径,自定义
-DMYSQL_DATADIR=/home/system_username/mysql/mysqldata

//mysql配置文件地址------The default my.cnf option file directory
-DSYSCONFDIR=/etc

//Compile storage engine xxx statically into server
/*Storage engines are built as plugins. You can build a plugin as a static module (compiled into the server)
*or a dynamic module (built as a dynamic library that must be installed into the server using the INSTALL
*PLUGIN statement or the --plugin-load option before it can be used). Some plugins might not support static
*or dynamic building.
*/
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_FEDERATED_STORAGE_ENGINE=1
-DWITH_PARTITION_STORAGE_ENGINE=1

//Unix socket file
/*
*The Unix socket file path on which the server listens for socket connections. This must be an absolute path
*name. The default is /tmp/mysql.sock
*/
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock

//数据库服务器TCP/IP连接的监听端口,默认为3306
-DMYSQL_TCP_PORT=3306

//Whether to enable LOCAL capability in the client library for LOAD DATA INFILE
//默认为关闭,这里开启
-DENABLED_LOCAL_INFILE=1

//数据库编码设置
-DEXTRA_CHARSETS=all
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8-general_ci
3.编译和安装
----shell定位到源代码文件夹目录
----执行:(编译用了大概20分钟)
shell:~$ make
shell:~$ make install

4.后续配置
----进入mysql安装目录下的脚本目录
shell:~$ cd /usr/local/mysql/scripts
----利用mysql_install_db脚本生成新的MySQL 授权表
./mysql_install_db --basedir=/usr/local/mysql --datadir=/home/system_username/Programming/mysql/mysqldata
--user=mysql
----进入mysql安装目录下的支持文件目录
shell:~$ cd /usr/local/mysql/support-files
----复制mysql配置文件
shell:~$ sudo cp my-medium.cnf /etc/my.cnf

----复制服务文件并修改
shell:~$ sudo cp mysql.server mysqld
----修改mysqld
basedir=/usr/local/mysql
datadir=/home/mysql
mv mysqld /etc/init.d/mysqld
----启动服务
shell:~$ service mysqld start
----关闭服务
shell:~$ service mysqld stop
---------------------------------
service命令:
1. 用于管理Linux系统中服务的命令
2. 作用是去/etc/init.d目录下寻找相应的服务,进行开启和关闭等操作
3. 上述操作后,mysqld服务文件对应mysql.server文件
---------------------------------
----添加服务到自启动项
shell:~$ sudo chkconfig --level 3 mysqld on

----设置软连接使mysql, mysqldump, mysqladmin这三个命令能在shell中直接运行
shell:~$ sudo ln -s /usr/local/mysql/bin/mysql /usr/bin
shell:~$ sudo ln -s /usr/local/mysql/bin/mysqldump /usr/bin
shell:~$ sudo ln -s /usr/local/mysql/bin/mysqladmin /usr/bin
---------------------------------
=>mysql数据库中文乱码解决 :
1. 乱码分析
----从终端shell进入mysql
shell:~$ mysql
............
............
mysql> show variables like '%character%'
----得到以下数据库编码信息表:
+----------------------------------- +-------------------------------------------+
| Variable_name | Value |
+------------------------------------+-------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql/share/charsets/ |
+------------------------------------ +-------------------------------------------+
可以看出character_set_database ,character_set_server 的编码还是默认的latin1。
不知道为什么,之前DEFAULT_CHARSET设置成为utf8的,好像没起作用。查看官方文档
发现,character_set_database不支持配置文件(/etc/my.cnf)变量设置,
但是character_set_server 支持配置文件变量设置。

2. 解决办法
----打开配置文件
shell:~$ sudo gedit /etc/my.cnf
然后在[mysqld]配置选项下添加
character-set-server = utf8
----然后进入mysql
执行:
mysql> show variables like '%character%'
结果:character_set_database ,character_set_server两项都变为utf8了
----测试:
往数据库表中插入中文字段,中文就正常显示了。

注:1.用5.1版本的时候如下方法是可以解决中文编码问题的
----在配置文件[mysqld]和[client]节下分别添加: default-character-set = utf8
2.不知到是不是手动编译的原因,在5.5.8中配置文件中用上述方法会造成数据库服务无法启动。
----错误日志如下:( datadir/username.err为错误日志文件)
----------------------------------------------------
mysqld_safe mysqld from pid file /home/cyberwym/Programming/mysql/mysqldata/cyberwym.pid ended
...........
...........
[ERROR] /usr/local/mysql/bin/mysqld: unknown variable 'default-character-set=utf8'
[ERROR] Aborting
----------------------------------------------------
----这样会造成pid文件(datadir/username.pid)无法更新
----在配置文件[mysqld]和[client]节下分别去掉: default-character-set = utf8 后,数据库服务就启动正常了

bitsCN.com
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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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 use docker desktop How to use docker desktop Apr 15, 2025 am 11:45 AM

How to use Docker Desktop? Docker Desktop is a tool for running Docker containers on local machines. The steps to use include: 1. Install Docker Desktop; 2. Start Docker Desktop; 3. Create Docker image (using Dockerfile); 4. Build Docker image (using docker build); 5. Run Docker container (using docker run).

Difference between centos and ubuntu Difference between centos and ubuntu Apr 14, 2025 pm 09:09 PM

The key differences between CentOS and Ubuntu are: origin (CentOS originates from Red Hat, for enterprises; Ubuntu originates from Debian, for individuals), package management (CentOS uses yum, focusing on stability; Ubuntu uses apt, for high update frequency), support cycle (CentOS provides 10 years of support, Ubuntu provides 5 years of LTS support), community support (CentOS focuses on stability, Ubuntu provides a wide range of tutorials and documents), uses (CentOS is biased towards servers, Ubuntu is suitable for servers and desktops), other differences include installation simplicity (CentOS is thin)

How to view the docker process How to view the docker process Apr 15, 2025 am 11:48 AM

Docker process viewing method: 1. Docker CLI command: docker ps; 2. Systemd CLI command: systemctl status docker; 3. Docker Compose CLI command: docker-compose ps; 4. Process Explorer (Windows); 5. /proc directory (Linux).

What to do if the docker image fails What to do if the docker image fails Apr 15, 2025 am 11:21 AM

Troubleshooting steps for failed Docker image build: Check Dockerfile syntax and dependency version. Check if the build context contains the required source code and dependencies. View the build log for error details. Use the --target option to build a hierarchical phase to identify failure points. Make sure to use the latest version of Docker engine. Build the image with --t [image-name]:debug mode to debug the problem. Check disk space and make sure it is sufficient. Disable SELinux to prevent interference with the build process. Ask community platforms for help, provide Dockerfiles and build log descriptions for more specific suggestions.

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

Detailed explanation of docker principle Detailed explanation of docker principle Apr 14, 2025 pm 11:57 PM

Docker uses Linux kernel features to provide an efficient and isolated application running environment. Its working principle is as follows: 1. The mirror is used as a read-only template, which contains everything you need to run the application; 2. The Union File System (UnionFS) stacks multiple file systems, only storing the differences, saving space and speeding up; 3. The daemon manages the mirrors and containers, and the client uses them for interaction; 4. Namespaces and cgroups implement container isolation and resource limitations; 5. Multiple network modes support container interconnection. Only by understanding these core concepts can you better utilize Docker.

vscode cannot install extension vscode cannot install extension Apr 15, 2025 pm 07:18 PM

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

What is vscode What is vscode for? What is vscode What is vscode for? Apr 15, 2025 pm 06:45 PM

VS Code is the full name Visual Studio Code, which is a free and open source cross-platform code editor and development environment developed by Microsoft. It supports a wide range of programming languages ​​and provides syntax highlighting, code automatic completion, code snippets and smart prompts to improve development efficiency. Through a rich extension ecosystem, users can add extensions to specific needs and languages, such as debuggers, code formatting tools, and Git integrations. VS Code also includes an intuitive debugger that helps quickly find and resolve bugs in your code.

See all articles