温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

MySQL5.5源码安装的流程

发布时间:2021-09-16 16:35:36 来源:亿速云 阅读:115 作者:chen 栏目:MySQL数据库

这篇文章主要讲解了“MySQL5.5源码安装的流程”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“MySQL5.5源码安装的流程”吧!

源码安装的系统需求:
MySQL的源码安装需要下面的一些开发工具。

CMake 用来在所有平台上构建框架
优秀的 make 程序。推荐使用GNU make 3.75或更新的版本。
ANSI C++编辑器。GCC 4.2.1或更高版本,Sun Studio 12或更新的版本, Visual Studio 2008或更新的版本。
需要足够的内存。如果当在编译大的源文件时报"internal compiler error",则可能是系统的内存太小了。
如果你要运行测试脚本,需要安装Perl。大多数的类Unix系统包含Perl。在Windows系统下,可以安装ActiveState Perl。

安装需要的包

[root@localhost ~]# yum install gcc-c++
[root@localhost ~]# yum install libaio-devel
[root@localhost ~]# yum install ncurses-devel
[root@localhost ~]# yum install numactl-devel
[root@localhost ~]# yum install openssl-devel
[root@localhost ~]# yum install gperf

安装rpm-build包
[root@localhost yum.repos.d]# yum install rpm-build

安装cmake2.8.2
去https://cmake.org/download/下载cmake的源码安装包
[root@localhost install]# wget http://www.cmake.org/files/v2.8/cmake-2.8.2.tar.gz --no-check-certificate

解压
[root@localhost install]# gzip -d cmake-2.8.2.tar.gz
[root@localhost install]# tar fvx cmake-2.8.2.tar

[root@localhost install]# cd cmake-2.8.2
[root@localhost cmake-2.8.2]# ./bootstrap

编译安装
[root@localhost cmake-2.8.2]# make
[root@localhost cmake-2.8.2]# make install

查看版本
[root@localhost cmake-2.8.2]# cmake -version
cmake version 2.8.2

如果创建二进制rpm安装文件,则通过下面命令生成
[root@localhost install]# rpmbuild --rebuild --clean MySQL-5.5.48-1.el6.src.rpm --define='runselftest 0'

查看生成的RPM文件
[root@localhost x86_64]# cd /root/rpmbuild/RPMS/x86_64
[root@localhost x86_64]# ll
total 142788
-rw-r--r--. 1 root root 15333376 Mar 28 23:11 MySQL-client-5.5.48-1.linux2.6.x86_64.rpm
-rw-r--r--. 1 root root  4992448 Mar 28 23:12 MySQL-devel-5.5.48-1.linux2.6.x86_64.rpm
-rw-r--r--. 1 root root 51994352 Mar 28 23:12 MySQL-embedded-5.5.48-1.linux2.6.x86_64.rpm
-rw-r--r--. 1 root root 39075180 Mar 28 23:11 MySQL-server-5.5.48-1.linux2.6.x86_64.rpm
-rw-r--r--. 1 root root  1753148 Mar 28 23:12 MySQL-shared-5.5.48-1.linux2.6.x86_64.rpm
-rw-r--r--. 1 root root 33055692 Mar 28 23:12 MySQL-test-5.5.48-1.linux2.6.x86_64.rpm

如果编译源码方式安装,则执行下面命令

[root@localhost install]# rpm -ivh MySQL-5.5.48-1.el6.src.rpm 
warning: MySQL-5.5.48-1.el6.src.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
   1:MySQL                  ########################################### [100%]

手动创建Mysql用户和组
[root@localhost install]# groupadd mysql
[root@localhost install]# useradd -r -g mysql -s /bin/false mysql

解压生成的包
[root@localhost SOURCES]# cd /root/rpmbuild
[root@localhost rpmbuild]# ls -trl
total 24
drwxr-xr-x. 2 root root 4096 Mar 28 05:02 SRPMS
drwxr-xr-x. 3 root root 4096 Mar 28 23:11 RPMS
drwxr-xr-x. 2 root root 4096 Mar 28 23:12 BUILDROOT
drwxr-xr-x. 2 root root 4096 Mar 28 23:12 BUILD
drwxr-xr-x. 2 root root 4096 Mar 28 23:41 SPECS
drwxr-xr-x. 3 root root 4096 Mar 28 23:46 SOURCES
[root@localhost rpmbuild]# cd SOURCES/
[root@localhost SOURCES]# ls -trl
total 20712
-rw-r--r--.  1 root root  21201193 Jan 14 18:48 mysql-5.5.48.tar.gz
[root@localhost SOURCES]# tar zxvf mysql-5.5.48.tar.gz 

开始编译
[root@localhost SOURCES]# ll
total 20712
drwxr-xr-x. 31 7161 wheel     4096 Jan 14 18:47 mysql-5.5.48
-rw-r--r--.  1 root root  21201193 Jan 14 18:48 mysql-5.5.48.tar.gz
[root@localhost SOURCES]# cd mysql-5.5.48

[root@localhost mysql-5.5.48]# cmake . -DCMAKE_INSTALL_PREFIX=/software \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DCOMPILATION_COMMENT='production environment' \
-DWITH_READLINE=ON \
-DSYSCONFDIR=/software \
-DMYSQL_UNIX_ADDR=/data/mysql.sock \
-DMYSQL_DATADIR=/data


[root@localhost mysql-5.5.48]# make
Linking CXX executable mysql_tzinfo_to_sql
[100%] Built target mysql_tzinfo_to_sql
Scanning dependencies of target mysqld
[100%] Building CXX object sql/CMakeFiles/mysqld.dir/main.cc.o
Linking CXX executable mysqld
[100%] Built target mysqld
Scanning dependencies of target udf_example
[100%] Building C object sql/CMakeFiles/udf_example.dir/udf_example.c.o
Linking C shared module udf_example.so
[100%] Built target udf_example
Scanning dependencies of target my_safe_process
[100%] Building CXX object mysql-test/lib/My/SafeProcess/CMakeFiles/my_safe_process.dir/safe_process.cc.o
Linking CXX executable my_safe_process
[100%] Built target my_safe_process

[root@localhost mysql-5.5.48]# make install
-- Installing: /data/man/man1/perror.1
-- Installing: /data/man/man1/mysqld_multi.1
-- Installing: /data/man/man1/mysql_client_test_embedded.1
-- Installing: /data/man/man1/msql2mysql.1
-- Installing: /data/man/man1/mysqlman.1
-- Installing: /data/man/man1/comp_err.1
-- Installing: /data/man/man8/mysqld.8

[root@localhost software# cd /software
[root@localhost software# ll
total 220
drwxr-xr-x.  2 root root   4096 Mar 29 00:06 bin
-rw-r--r--.  1 root root  17987 Jan 14 18:38 COPYING
drwxr-xr-x.  3 root root   4096 Mar 29 00:05 data
drwxr-xr-x.  2 root root   4096 Mar 29 00:05 docs
drwxr-xr-x.  3 root root   4096 Mar 29 00:05 include
-rw-r--r--.  1 root root 151708 Jan 14 18:47 INSTALL-BINARY
drwxr-xr-x.  3 root root   4096 Mar 29 00:05 lib
drwxr-xr-x.  4 root root   4096 Mar 29 00:06 man
drwxr-xr-x. 10 root root   4096 Mar 29 00:06 mysql-test
-rw-r--r--.  1 root root   2496 Jan 14 18:38 README
drwxr-xr-x.  2 root root   4096 Mar 29 00:06 scripts
drwxr-xr-x. 27 root root   4096 Mar 29 00:06 share
drwxr-xr-x.  4 root root   4096 Mar 29 00:06 sql-bench
drwxr-xr-x.  2 root root   4096 Mar 29 00:06 support-files

更改MySQL安装软件的权限为mysql
[root@localhost software]# chown -R mysql .
[root@localhost software]# chgrp -R mysql .

初始化MySQL数据库的数据文件路径,并且创建系统表

[root@localhost data]# scripts/mysql_install_db --user=mysql  --datadir=/data
Installing MySQL system tables...
160329  0:21:08 [Note] ./bin/mysqld (mysqld 5.5.48) starting as process 25151 ...
OK
Filling help tables...
160329  0:21:08 [Note] ./bin/mysqld (mysqld 5.5.48) starting as process 25158 ...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

./bin/mysqladmin -u root password 'new-password'
./bin/mysqladmin -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:
./bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd . ; ./bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd ./mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

[root@localhost software]# chown -R root .
[root@localhost software]# chown -R mysql data

[root@localhost mysql]# cp support-files/my-medium.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf'? y

启动数据库
发生报错
[root@localhost data]# ./bin/mysqld_safe --defaults-file=/etc/my.cnf &
[1] 1053
[root@localhost data]# 160330 01:36:51 mysqld_safe Logging to '/var/log/mysqld.log'.
160330 01:36:51 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
160330 01:36:52 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

[1]+  Done                    bin/mysqld_safe --user=mysql

查看报错日志,报错原因是mysql没有指定路径的读写权限,导致无法创建进程文件
[root@localhost data]# vim /var/log/mysqld.log
160330  1:36:52 [ERROR] /data/bin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 13)
160330  1:36:52 [ERROR] Can't start server: can't create PID file: Permission denied

创建对应路径,并授权

[root@localhost install]# mkdir -p /var/run/mysqld/
[root@localhost install]# chown -R mysql.mysql /var/run/mysqld/

[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql.server

编辑配置文件

[root@localhost mysql]# vim /etc/my.cnf
[client]
port = 3306
socket = /data/mysql.sock

# Mysql server
[mysqld]
port = 3306
user = mysql
socket = /data/mysql.sock
pid-file = /var/run/mysqld/mysqld.pid
basedir = /software
datadir = /data
#tmpdir = 
open_files_limit = 10240
sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

# Buffer
max_allowed_packet = 256M
max_heap_table_size = 256M
net_buffer_length = 8K
sort_buffer_size = 4M
join_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 16M

# Log
log-bin = /log/binlog/mysql-bin
binlog_cache_size = 32M
max_binlog_cache_size = 512M
max_binlog_size = 512M
binlog_format = MIXED
log_output = FILE
log_error = /log/err.log
slow_query_log = 1
slow_query_log_file = /log/slow_query.log
general_log = 0
general_log_file = /log/general_query.log

# InnoDB
innodb_data_file_path = ibdata1:12M:autoextend
#innodb_log_file_size = 256M
#innodb_log_files_in_group = 3
innodb_buffer_pool_size = 100M

# Character set
#character_set_server = gbk
#collation_server = gbk_bin

[mysql]
no-auto-rehash
default-character-set = gbk

启动MySQL数据库

[root@localhost data]# ./bin/mysqld_safe --defaults-file=/etc/my.cnf &
[1] 5774

[root@localhost data]# 160330 01:37:51 mysqld_safe Logging to '/var/log/mysqld.log'.

160330 01:37:51 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

[root@localhost data]# ps -ef|grep mysql
root      1231 55613  0 01:37 pts/2    00:00:00 /bin/sh bin/mysqld_safe --user=mysql
mysql     1401  1231  0 01:37 pts/2    00:00:00 /data/bin/mysqld --basedir=/data --datadir=/var/lib/mysql --plugin-
dir=/data/lib/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --
socket=/var/lib/mysql/mysql.sock
root      1421 55613  0 01:38 pts/2    00:00:00 grep mysql

更改root用户密码
[root@localhost data]# ./bin/mysqladmin -u root password 'Mysql#2015'

删除数据库中多余的root用户和匿名用户,只在本地保留一个root用户
mysql> delete from mysql.user where (user,host) not in (select 'root','localhost');
Query OK, 4 rows affected (0.00 sec)

更改root的用户名
mysql> update mysql.user set user='system',password=password('Mysql#2015') where user='root';
Query OK, 1 row affected (0.09 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> truncate table mysql.db;
Query OK, 0 rows affected (0.00 sec)

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

感谢各位的阅读,以上就是“MySQL5.5源码安装的流程”的内容了,经过本文的学习后,相信大家对MySQL5.5源码安装的流程这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI