Installing MySQL Server
Installing MySQL Server
Here we will learn how to Compile and Install the MySQL Server from source code. After that we will Configure our server for basic functionality and Secure it for general usage. Finally we will discuss the Basics of MySQL Server.
Installing MySQL Server from source code involves the following steps.
1) Installing missing dependencies – 1st
2) Adding a MySQL User and Group
3) Downloading the source code
4) Unpacking & Installing
5) Post Installation Procedures
6) Installing missing dependencies – 2nd
7) Installation Review
After installing MySQL Server, it is recommended to view the following sections.
Securing MySQL Server
Customizing MySQL Server
Basics of MySQL Server
1) Installing missing dependencies
Perl-GD support for MySQL Server requires installation of Perl-GD package. Installation instructions here.
2) Adding a MySQL User and group
Running the MySQL Server as root user is insecure and so not advisable. It is better to run the MySQL Server under a system account with limited privileges. So we will create a User and Group for MySQL.
In the terminal, execute the following command.
# useradd -r -U mysql -M -d /usr/local/mysql/data
NOTE: The home directory of mysql user is set to the data directory /usr/local/mysql/data/. This is because we plan to install MySQL Server in the directory /usr/local/mysql/. You can use a different directory for installation or data storage, if you wish.
OPTIONS EXPLAINED -U
Create a group with the same name as the user and add the user to this group, in case USERGROUPS_ENAB in your /etc/login.defs is set to no. (By default this is set to yes). -r
Create as system account -M
Do not create the user´s home directory, in case CREATE_HOME in your /etc/login.defs is set to yes. (By default this is set to no). This is used because we do not want the files and directories contained in the skeleton directory to be copied to home directory. -d
The new user will be created using HOME_DIR as the value for the user´s login directory. The default is to append the LOGIN name to BASE_DIR and use that as the login directory name. The directory HOME_DIR does not have to exist but will not be created if it is missing.
This will create a user and group, both named as mysql. They will be created as system accounts and there will be no password set. The home directory will be set to /usr/local/mysql/data/ but it will not be created. The login shell will be /bin/bash.
3) Downloading the source code
Download the MySQL Community Server source code
MySQL Community Server is the freely downloadable version of MySQL Server. It is available from the MySQL Developer Zone.
Let us goto http://dev.mysql.com/downloads/. On the top of page, click on the Downloads tab, which will take us to the download page listing different MySQL projects. Below MySQL Community Server, click on the DOWNLOAD link, which will take us to the download page. We will see a list of Generally Available (GA) Releases. Select Platform as Source Code. Scroll to the bottom and we will see Generic Linux (Architecture Independent), Compressed TAR Archive. Click the Download
button, which will take us to a page where we can Login/SignUp with an
Oracle Web account. If you want, you can. But I chose to click on No thanks, just start my download.. This will start the download.
The downloaded file mysql-5.6.19.tar.gz will be 31.4 MB in size.
Download the Google C++ Mocking Framework source code
Google C++ Mocking Framework(gmock) is a library for writing and using C++ mock classes. MySQL Server uses it for Google C++ Testing Framework(gtest) based unit tests. If you do not download this now, the following error will be dispalyed during the configure process.
Googlemock 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.
Even if you enable the option ENABLE_DOWNLOADS=1 (that is, assuming you have an active internet connection), configure script will give you the following error.
CMake Error: Problem with tar_extract_all(): Invalid argument
CMake Error: Problem extracting tar: /usr/src/mysql-5.6.19/source_downloads/gmock-1.6.0.zip
This occurs due to MySQL Bug 69854, which will be fixed on MySQL 5.7.4 Milestone 14. For the current time, we have to fix this by hand.
Google C++ Mocking Framework is available at Google Code Project Hosting. Goto http://code.google.com/p/googlemock/. On the top of page, click on the Downloads tab, which will take us to the page with download listing. The version of Google C++ Mocking Framework, which configure script tries to download is 1.6.0. So click on gmock-1.6.0.zip, which will take us to the download page. Click on gmock-1.6.0.zip. This will start the download.
The downloaded zip file gmock-1.6.0.zip is 2.0 MB in size.
4) Unpacking & Installing
Unpacking
Make sure you have copied the downloaded files mysql-5.6.19.tar.gz and gmock-1.6.0.zip to directory /usr/src/. In the terminal, change to /usr/src/ directory.
# cd /usr/src
Extract the gzipped tarball containing MySQL Server.
# tar -zxvf mysql-5.6.19.tar.gz
OPTIONS EXPLAINED -x
extract files from an archive -v
verbosely list files processed -z
filter the archive through gzip -f
use archive file or device ARCHIVE
Extract the gmock zip file into specified directory
# unzip gmock-1.6.0.zip -d mysql-5.6.19/source_downloads
OPTIONS EXPLAINED -d
An optional directory to which to extract files. By default, all files and subdirectories are recreated in the current directory; the -d option allows extraction in an arbitrary directory (always assuming one has permission to write to the directory). This option need not appear at the end of the command line; it is also accepted before the zipfile specification (with the normal options), immediately after the zipfile specification, or between the file(s) and the -x option. The option and directory may be concatenated without any white space between them, but note that this may cause normal shell behavior to be suppressed. In particular, ‘‘-d ~’’ (tilde) is expanded by Unix C shells into the name of the user’s home directory, but ‘‘-d~’’ is treated as a literal subdirectory ‘‘~’’ of the current directory.
This will create a directory named source_downloads in the mysql-5.6.19 directory and extract the conents of zip file into it.
Installing
NOTE: Installation is performed based on the rules iRULE1 and iRULE3.
Now we will have a directory mysql-5.6.19 with the extracted files. Change to that directory in terminal.
# cd mysql-5.6.19
Execute cmake.
NOTE:
• The default install directory is /usr/local/mysql/. If you want to change it, use the option CMAKE_INSTALL_PREFIX.
example: # cmake . -DCMAKE_INSTALL_PREFIX=your_custom_location
• The default data directory is /usr/local/mysql/data/. If you want to change it, use the option MYSQL_DATADIR.
example: # cmake . -DMYSQL_DATADIR=your_custom_location
• To see the default configure options for our installation, use the below command
command: # cmake . -LH
• To see the complete list of configure options, see the following link
http://dev.mysql.com/doc/mysql-sourcebuild-excerpt/5.6/en/source-configuration-options.html
# cmake .
cmake will check our system for required dependencies, assigns values for system-dependent variables and use these values to generate the Makefile.
Execute make.
# make
make will look at our Makefile, compile our program code and create the executables in the sequence described.
Execute make install.
# make install
OPTIONS EXPLAINED install
install will look for the target install in Makefile, and install MySQL Server to the specified location.
5) Post Installation Procedures
Adding MySQL Server executables to system PATH
MySQL Server executables are located at /usr/local/mysql/bin/ and they are 43 in number. We are not going add symbolic links for each of them to /usr/bin/. Instead we will add /usr/local/mysql/bin/ to the system PATH variable.
PATH is an
Environment variable and it must be available to all users; both in
login and non-login shells. For this we must add a script in the /etc/profile.d/ directory.
NOTE:
• Read the difference between Environment Variable and Local Variable.
• Read the difference between Login Shell and Non login Shell.
Create a file mysql.sh in /etc/profile.d/ directory with the below content.
This is for the Bash shell.
if ! echo ${PATH} | /bin/grep -q /usr/local/mysql/bin ; then
PATH=/usr/local/mysql/bin:${PATH}
fi
Create a file mysql.csh in /etc/profile.d/ directory with the below content.
This is for C shell and Tenex C shell.
if ( "${path}" !~ */usr/local/mysql/bin* ) then
set path = ( /usr/local/mysql/bin $path )
endif
From this moment on, any new login shells or non-login shells spawned will have /usr/local/mysql/bin/ in the PATH variable. But the current shell on which we are working does not have it. Because it was spawned before the script was placed in the global profile directory. So we will have to source the script on our working shell.
I am using the Bash shell. So I executed the following command on my current terminal.
# source /etc/profile.d/mysql.sh
Adding MySQL Server libraries to the shared library cache
MySQL Server libraries are located at /usr/local/mysql/lib/.
But these are not shared yet. For other applications to find these
libraries at runtime, the dynamic linker cache in Linux must be updated
with the information about these libraries.
Create a file mysql.conf in the directory /etc/ld.so.conf.d/ with the entry /usr/local/mysql/lib
# echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf
Run ldconfig.
# ldconfig
ldconfig scans the ld.so.conf.d folder and updates the shared library cache; so that dynamic linker can find them during runtime.
Adding MySQL Server manpages to the MANPATH
MySQL Server manpages are located at /usr/local/mysql/man/. We have already added /usr/local/mysql/bin/ to the system PATH variable. So man tool will automatically search the location /usr/local/mysql/man/ for manpages. No extra changes need to be made.
Creating the MySQL Server grant tables
In the terminal, change to MySQL Server install directory
# cd /usr/local/mysql
Change the owner and group of /usr/local/mysql/ directory and it’s contents to mysql. This is done for installing the MySQL Server‘s system grant tables. We will be reverting the permissions after that.
# chown -R mysql:mysql .
OPTIONS EXPLAINED -R
operate on files and directories recursively
Create the MySQL Server grant tables. Execute the script mysql_install_db as mysql user.
# scripts/mysql_install_db --user=mysql
OPTIONS EXPLAINED --user
The login username to use for running mysqld. Files and directories created by mysqld will be owned by this user. You must be root to use this option. By default mysqld runs using your current login name and files and directories that it creates will be owned by you.
Change back the owner and group of /usr/local/mysql/ directory and it’s contents to root.
# chown -R root .
OPTIONS EXPLAINED -R
operate on files and directories recursively
Change the owner of /usr/local/mysql/ directory to mysql.
# chown -R mysql data
OPTIONS EXPLAINED -R
operate on files and directories recursively
The data directory has already it’s group ownership set to mysql. With this command both the group and owner of /usr/local/mysql/data/ directory will be set to mysql.
Remove the permissions for group and others on /usr/local/mysql/data/ directory. So that only mysql will have access to it.
# chmod -R go-rwx data
OPTIONS EXPLAINED -R
operate on files and directories recursively go-rwx
Remove read,write & execute permissions for group & others
Setting the configuration file
Copy the default configuration file my-default.cnf into /etc/ directory and rename it to my.cnf.
# cp support-files/my-default.cnf /etc/my.cnf
Open the MySQL Server configuration file /etc/my.cnf. We have to make certain changes for the server to work properly.
NOTE: If you have changed the location of MySQL Server install directory or data directory
The default install directory for MySQL Server is /usr/local/mysql/. And the default data directory for MySQL Server is /usr/local/mysql/data/. If you have changed any of them, make sure to make the appropriate changes to the values basedir and datadir.
Setting the MySQL user
MySQL Server by default runs as the user root. Running MySQL Server as the root user is insecure and so not advisable. So will set MySQL Server to run as the standard user mysql. Just below the [mysqld] section add a new line as shown below.
user = mysql
Configuring the IP to which MySQL Server binds
MySQL Server by default binds to all IP addresses on all interfaces of a given system. If we want MySQL Server to bind on only a given IP address, we must configure as follows. Under the [mysqld] section, add the following line with the IP address you want to bind to.
NOTE: Replace 192.168.0.100 with the IP address of your machine.
bind-address = 192.168.0.100
This makes MySQL Server to bind to IP address 192.168.0.100.
NOTE: If we want MySQL Server to
bind to a selected set of interfaces only, we can leave MySQL Server to
it’s default behaviour, with firewalling off the interfaces we do not
want to bind to.
Initializing the MySQL Server grant tables.
Execute mysqld_safe as mysql user.
# mysqld_safe --user=mysql &
OPTIONS EXPLAINED --user
Run the mysqld server as the user having the name user_name or the numeric user ID user_id. (“User” in this context refers to a system login account, not a MySQL user listed in the grant tables.)
mysqld_safe is the recommended way to start a mysqld server on UNIX and NetWare. It initializes the mysql grant tables containing the privileges that determine how users are permitted to connect to the server. mysqld_safe also adds some safety features such as restarting the server when an error occurs and logging runtime information to an error log file.
NOTE: Prepending &
to the command, moves the command to background and gives us the
terminal back for further jobs. If the command spits out standard output
after the service is running, just press CTRL-C or close that terminal and open a new one.
Setting the MySQL Server service
Copy the MySQL Server daemon start/stop script mysql.server to /etc/rc.d/init.d/ directory and rename it to mysql.
# cp -v support-files/mysql.server /etc/rc.d/init.d/mysql
OPTIONS EXPLAINED -v
explain what is being done
Add mysql as a Sys V init service.
# chkconfig --add mysql
OPTIONS EXPLAINED --add
This option adds a new service for management by chkconfig. When a new service is added, chkconfig ensures that the service has either a start or a kill entry in every runlevel. If any runlevel is missing such an entry, chkconfig creates the appropriate entry as specified by the default values in the init script. Note that default entries in LSB-delimited ’INIT INFO’ sections take precedence over the default runlevels in the initscript; if any Required-Start or Required-Stop entries are present, the start and stop priorities of the script will be adjusted to account for these dependencies.
This option adds mysql as a Sys V init service to be managed by chkconfig. When a new service is added, chkconfig ensures that the service has either a start or a kill entry in every runlevel. If any runlevel is missing such an entry, chkconfig creates the appropriate entry as specified by the default values in the init script.
chkconfig also creates the following softlinks for our mysql script to the corresponding runlevel directories.
/etc/rc.d/rc0.d/K36mysql
/etc/rc.d/rc1.d/K36mysql
/etc/rc.d/rc2.d/S64mysql
/etc/rc.d/rc3.d/S64mysql
/etc/rc.d/rc4.d/S64mysql
/etc/rc.d/rc5.d/S64mysql
/etc/rc.d/rc6.d/K36mysql
NOTE:
K36mysql – K stands for
Kill. 36 implies mysql will be killed in 36th of the order. This is
intended for runlevels 0(shutdown), 1(single-user mode), 6(reboot). So mysql service will be killed in runlevels 0, 1 and 6.
S64mysql – S stands for
Start. 64 implies mysql will be started in 64th of the order. This is
intended for GUI/custom runlevels 2, 3, 4, 5. So mysql service will be started in runlevels 2, 3, 4 and 5.
Finally, start the mysql service.
# service mysql start
OPTIONS EXPLAINED start
starts the specified service
6) Installing missing dependencies
Still, there is one thing unfinished – MySQL Benchmark Suite.
MySQL Server comes with the MySQL Benchmark Suite, which is installed in /usr/local/mysql/sql-bench/. It can benchmark our MySQL Server and tell whether a given implementation performs well or poorly. The benchmark scripts are written in Perl and uses the DBI module to access database servers.
So we need the following to run MySQL Benchmark Suite – Perl, DBI and DBD::mysql. Of the above three, Perl and DBI are installed except DBD::mysql. We did not install DBD::mysql before installing MySQL Server, because DBD::mysql needs MySQL Server to be present prior to it’s installation.
To install DBD::mysql, follow the installation instructions here.
NOTE: Read more about DBI and libdbi.
7) Installation Review
Install location
/usr/local/mysql/
PID file
Syntax: /usr/local/mysql/data/HOSTNAME.pid
Example: /usr/local/mysql/data/example.com.pid
Socket file
/tmp/mysql.sock
Service file
/etc/rc.d/init.d/mysql
Default Port
3306
Executables
Listed and explained
Configuration files
Listed and explained
Log files
Listed and explained
Get information on Server status
Displays the status of MySQL service
# service mysql status
Displays the status of mysqld daemon
# mysqladmin -u root -p ping
Displays the status of server with variables
# mysqladmin -u root -p status
Display the status of server with variables and their values
# mysqladmin -u root -p extended-status
Get information on active Server threads
Displays a list of active server threads
# mysqladmin -u root -p processlist
Displays a list of active server threads with full processlist
# mysqladmin -u root -p -v processlist
Get information on Server variables
Displays a list of server system variables and their values
# mysqladmin -u root -p variables
Get information on Server version
# mysqladmin -u root -p version
After installing MySQL Server, it is recommended to view the following sections.
Securing MySQL Server
Customizing MySQL Server
Basics of MySQL Server
Installing MySQL Server的更多相关文章
- Installing MySQL Server on CentOS
MySQL is an open-source relational database. For those unfamiliar with these terms, a database is wh ...
- mysql Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’
mysql Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ 今天在linux中安装了mys ...
- installing mysql,this may take a few minutes,hold on plz wdcp卡住解决办法
centos6安装wdcp时make in progress卡住的解决办法 今天在一台centos6的vps上安装wdcp出现的这个问题,到安装程序滚动至下面这里时出现"卡死". ...
- percona innobackupex 遇到 connect to MySQL server as DBD::mysql module is not installed 问题
percona innobackupex connect to MySQL server as DBD::mysql module is not installed [root@mysql softw ...
- Installing MySQL 5.7.23 on CentOS 7
Installing MySQL 5.7.23 on CentOS 7 1. 安装前检查 1.1 检查NUMA是否开启 NUMA为什么要咋MySQL中禁用? MySQL是单进程多线程架构数据库,当nu ...
- 2003-Can't connect to mysql server on localhost (10061)
mysql数据库出现2003-Can't connect to mysql server on localhost (10061)问题 解决办法:查看wampserver服务器是否启动,如果没有启动启 ...
- ERROR 2003 (HY000): Can't connect to MySQL server on 'ip address' (111)的处理办法
远程连接mysql数据库时可以使用以下指令 mysql -h 192.168.1.104 -u root -p 如果是初次安装mysql,需要将所有/etc/mysql/内的所有配置文件的bind-a ...
- mySql 远程连接(is not allowed to connect to this MySQL server)
如果你想连接你的mysql的时候发生这个错误: ERROR 1130: Host '192.168.1.3' is not allowed to connect to this MySQL serve ...
- 报错:1130-host ... is not allowed to connect to this MySql server
报错:1130-host ... is not allowed to connect to this MySql server 解决方法: 1. 改表法. 可能是你的帐号不允许从远程登陆,只能在l ...
随机推荐
- iOS实用技能扩展-集成支付宝
前奏 现在随着移动开发的快速发展,移动支付变得越来越流行与必不可少.最近做了一个关于支付宝支付功能的应用,在使用支付宝的过程中,遇到一些不必要的弯路,因此,写了这篇文章总结一下关于iOS中如何开发使用 ...
- 字符串匹配算法-BM
在用于查找子字符串的算法中,BM(Boyer-Moore)算法是当前有效且应用比较广泛的一种算法,各种文本编辑器的“查找”功能(Ctrl+F),大多采用Boyer-Moore算法.比我们学习的KMP算 ...
- cocos2d-x plist+wen使用
http://zhan.renren.com/tag?value=cocos2dx&from=template http://blog.csdn.net/zhanglongit/article ...
- Notification与多线程
来源:南峰子(@南峰子_老驴 ) 链接:http://t.cn/R5swQcR 前几天与同事讨论到Notification在多线程下的转发问题,所以就此整理一下. 先来看看官方的文档,是这样写的: I ...
- Windows7服务无法启动的解决
这周六,我接到了一个很诡异的案例,表现为任务栏右下角网络连接图标始终为一个红叉,已排除网卡硬件.链路和网卡驱动的问题.主板都新换了一块,可是问题依旧,这无疑将问题的根源指向了操作系统.本想通过网络疑难 ...
- Linux Shell删除某一个目录下的所有文件夹(保留其他文件)
#!/bin/bash direc=$(pwd) for dir2del in $direc/* ; do if [ -d $dir2del ]; then rm -rf $dir2del fi do ...
- dhcp源码编译支持4G上网卡
1. tar xvzf dhcp-4.2.5-P1.tar.gz 2. ./configure --host=arm-linux ac_cv_file__dev_random=yes 3. vi bi ...
- C#百分比式布局
图一:原始窗口 图二:放大窗口 实现:窗体内添加一个panel1(Dock:Left),在窗体空余部分添加第二个panel2(Dock:Fill),窗体分为两部分. 在panel2内添加一个panel ...
- 总结如何实现Android浮动层,主要是dialog的使用
自定义一个类继承自Dialog类,然后在构造方法中,定义这个dialog的布局和一些初始化信息. 查看源码打印? 01 public class MenuDialog extends Dialog { ...
- A的ascll吗是多少?
//输入一个字符,返回他的ascll码 #include<stdio.h> int main() { char a; while(scanf("%c",&a)! ...