MYSQL学习篇之001-LINUX环境MYSQL源代码安装总结
以前主要使用MSSQL,ORACLE,SYBASE数据库,最近公司使用MYSQL,
开始参考官方文档REFMAN-5.6-EN.A4.PDF进行学习。本文主要是最近安装过程的一个总结。
采用源代码安装MYSQL5.6主要有以下工作要做:
2.1 安装 LIBAIO
3.1 使用GIT下载源代码
4.1 使用CMAKE生成MAKEFILE文件
4.2 编译源代码
5.1 建立用户与组
6 配置
6.1 修改 /etc/my.cnf
[root@FZ-Centos-23 mysql]# ln /usr/local/mysql/my.cnf /etc/my.cnf
[root@FZ-Centos-23 mysql]# vi /etc/my.cnf
6.2 添加到服务中
把文件/usr/local/mysql/support-files/mysql.server 复制一份到 /etc/init.d ,并重新命名为 mysqld,
并修改文件内的 basedir=/usr/local/mysql
datadir=/usr/local/msyql/data
# chkconfig mysqld on
7 启动
开始参考官方文档REFMAN-5.6-EN.A4.PDF进行学习。本文主要是最近安装过程的一个总结。
采用源代码安装MYSQL5.6主要有以下工作要做:
1 准备硬件(虚拟机)、操作系统(CENTOS)1 准备硬件(虚拟机)、操作系统(CENTOS)
2 安装编译源代码需要的一些工具软件与依赖库
3 下载源代码
4 编译源代码
5 安装
6 配置
7 启动
下面详细记录安装过程,方便以后再用。
虚拟机采用公司统一分配的帐号,操作系统信息为:
# uname -a2 安装编译源代码需要的一些工具软件与依赖库
Linux FZ-Centos-23 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
2.1 安装 LIBAIO
# yum install libaio
# yum search libaio2.2 安装 BISON
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
* base: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
base | 3.7 kB 00:00
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
updates/primary_db | 5.4 MB 00:03
====================================================== N/S Matched: libaio ======================================================
libaio.i686 : Linux-native asynchronous I/O access library
libaio.x86_64 : Linux-native asynchronous I/O access library
libaio-devel.i686 : Development files for Linux-native asynchronous I/O access
libaio-devel.x86_64 : Development files for Linux-native asynchronous I/O access
Name and summary matches only, use "search all" for everything.
2.3 安装 yum -y install gcc gcc-c++ autoconf make (略)
# yum install bison
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
* base: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package bison.x86_64 0:2.4.1-5.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=================================================================================================================================
Package Arch Version Repository Size
=================================================================================================================================
Installing:
bison x86_64 2.4.1-5.el6 base 637 k
Transaction Summary
=================================================================================================================================
Install 1 Package(s)
Total download size: 637 k
Installed size: 2.0 M
Is this ok [y/N]: y
Downloading Packages:
bison-2.4.1-5.el6.x86_64.rpm | 637 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : bison-2.4.1-5.el6.x86_64 1/1
Verifying : bison-2.4.1-5.el6.x86_64 1/1
Installed:
bison.x86_64 0:2.4.1-5.el6
Complete!
根据编译时提示,再安装缺少的依赖工具或库.3 下载源代码(存入/usr/loca/src/mysql)
3.1 使用GIT下载源代码
# git clone https://github.com/mysql/mysql-server.git3.2 查看当前分析,带*为活动状态
Initialized empty Git repository in /usr/local/src/mysql/mysql-server/.git/
remote: Counting objects: 1214340, done.
remote: Compressing objects: 100% (7/7), done.
Receiving objects: 100% (1214340/1214340), 1.01 GiB | 152 KiB/s, done.
remote: Total 1214340 (delta 0), reused 0 (delta 0), pack-reused 1214333
Resolving deltas: 100% (1005862/1005862), done.
[root@FZ-Centos-23 mysql-server]# pwd3.3设置分支为活动状态
/usr/local/src/mysql/mysql-server
[root@FZ-Centos-23 mysql-server]# git branch -r
origin/5.5
origin/5.6
origin/5.7
origin/8.0
origin/HEAD -> origin/5.7
origin/cluster-7.2
origin/cluster-7.3
origin/cluster-7.4
origin/cluster-7.5
[root@FZ-Centos-23 mysql-server]# git branch
* 5.7
[root@FZ-Centos-23 mysql-server]# git checkout 5.63.4 在源代码 mysql-server 同级目录下新建文件夹 bld 用于编译
Branch 5.6 set up to track remote branch 5.6 from origin.
Switched to a new branch '5.6'
[root@FZ-Centos-23 mysql-server]# git branch
* 5.6
5.7
mkdir bld4 编译源代码在源代码
cd bld
4.1 使用CMAKE生成MAKEFILE文件
CMake是一个跨平台的安装(编译)工具,可以用简单的语句来描述所有平台的安装 (编译过程)。
他能够输出各种各样的makefile或者project文件,能测试编译器所支持的C++特性,
类似UNIX下的automake。CMake 可以编译源代码、制作程式库、产生适配器(wrapper)、
还可以用任意的顺序建构执行档。CMake 支持 in-place 建构(二进档和源代码在同一个目录树中)
和 out-of-place 建构(二进档在别的目录里),
因此可以很容易从同一个源代码目录树中建构出多个二进档。
CMake 也支持静态与动态程式库的建构。
]# cmake ../mysql-server/
-- Running cmake version 3.8.0-rc2
-- Found Git: /usr/bin/git (found version "1.7.1")
-- The C compiler identification is GNU 4.4.7
-- The CXX compiler identification is GNU 4.4.7
-- Check for working C compiler: /usr/bin/cc
......
-- Using cmake version 3.8.0-rc2
-- Not building NDB
-- Performing Test HAVE_PEERCRED
-- Performing Test HAVE_PEERCRED - Success
-- Library mysqlclient depends on OSLIBS -lpthread;m;rt;dl
-- Googletest was not found. gtest-based unit tests will be disabled. You can run cmake . -DENABLE_DOWNLOADS=1 to automatically download and build required components from source.
-- If you are inside a firewall, you may need to use an https proxy: export https_proxy=http://example.com:80
-- Library mysqlserver depends on OSLIBS -lpthread;m;rt;crypt;dl
-- CMAKE_BUILD_TYPE: RelWithDebInfo
-- COMPILE_DEFINITIONS: HAVE_CONFIG_H
-- CMAKE_C_FLAGS: -Wall -Wextra -Wformat-security -Wvla -Wwrite-strings -Wdeclaration-after-statement
-- CMAKE_CXX_FLAGS: -Wall -Wextra -Wformat-security -Wvla -Woverloaded-virtual -Wno-unused-parameter
-- CMAKE_C_FLAGS_RELWITHDEBINFO: -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF
-- CMAKE_CXX_FLAGS_RELWITHDEBINFO: -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF
-- Configuring done
-- Generating done
-- Build files have been written to: /usr/local/src/mysql/bld
4.2 编译源代码
# make
Scanning dependencies of target gmock_main
[ 9%] Building CXX object googlemock/CMakeFiles/gmock_main.dir/__/googletest/src/gtest-all.cc.o
[ 18%] Building CXX object googlemock/CMakeFiles/gmock_main.dir/src/gmock-all.cc.o
[ 27%] Building CXX object googlemock/CMakeFiles/gmock_main.dir/src/gmock_main.cc.o
[ 36%] Linking CXX static library libgmock_main.a
[ 36%] Built target gmock_main
Scanning dependencies of target gmock
[ 45%] Building CXX object googlemock/CMakeFiles/gmock.dir/__/googletest/src/gtest-all.cc.o
[ 54%] Building CXX object googlemock/CMakeFiles/gmock.dir/src/gmock-all.cc.o
[ 63%] Linking CXX static library libgmock.a
[ 63%] Built target gmock
Scanning dependencies of target gtest
[ 72%] Building CXX object googlemock/gtest/CMakeFiles/gtest.dir/src/gtest-all.cc.o
[ 81%] Linking CXX static library libgtest.a
[ 81%] Built target gtest
Scanning dependencies of target gtest_main
[ 90%] Building CXX object googlemock/gtest/CMakeFiles/gtest_main.dir/src/gtest_main.cc.o
[100%] Linking CXX static library libgtest_main.a
[100%] Built target gtest_main
5 安装
5.1 建立用户与组
# groupadd mysql5.2 安装
# useradd -r -g mysql -s /bin/false mysql
配置 ,修改安装路径的用户属性
cd /usr/local
chown -R mysql:mysql mysql
# make install5.3 初始化数据
-- Installing: /usr/local/mysql/sql-bench/test-connect
-- Installing: /usr/local/mysql/sql-bench/test-create
-- Installing: /usr/local/mysql/sql-bench/test-insert
-- Installing: /usr/local/mysql/sql-bench/test-select
-- Installing: /usr/local/mysql/sql-bench/test-transactions
-- Installing: /usr/local/mysql/sql-bench/test-wisconsin
# cd /usr/local/mysql
# scripts/mysql_install_db --user=mysql
2017-03-29 18:31:42 4401 [Note] InnoDB: 5.6.35 started; log sequence number 1626027
2017-03-29 18:31:42 4401 [Note] Binlog end
2017-03-29 18:31:42 4401 [Note] InnoDB: FTS optimize thread exiting.
2017-03-29 18:31:42 4401 [Note] InnoDB: Starting shutdown...
2017-03-29 18:31:43 4401 [Note] InnoDB: Shutdown completed; log sequence number 1626037
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 FZ-Centos-23 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/
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
New default config file was created as ./my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
6 配置
6.1 修改 /etc/my.cnf
[root@FZ-Centos-23 mysql]# ln /usr/local/mysql/my.cnf /etc/my.cnf
[root@FZ-Centos-23 mysql]# vi /etc/my.cnf
6.2 添加到服务中
把文件/usr/local/mysql/support-files/mysql.server 复制一份到 /etc/init.d ,并重新命名为 mysqld,
并修改文件内的 basedir=/usr/local/mysql
datadir=/usr/local/msyql/data
# chkconfig mysqld on
7 启动
8 初始化root密码
service mysqld start
service mysqld stop
/usr/local/mysql/bin/mysqladmin -u root -h localhost password '123456'
或
mysql> use mysql
mysql> UPDATE user SET password=PASSWORD('123456') WHERE user='root';
root密码忘记问题处理
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passwor YES)
解决办法:
vi /etc/my.cnf
在 [mysqld]
下增加一行
skip-grant-tables
保存退出,重新启动MYSQL