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 ...
 
随机推荐
- btrace 笔记
			
转载请注明原链接地址 http://www.cnblogs.com/dongxiao-yang/p/6134393.html btrace 是一个可以不用重启线上java业务查问题的神器,记一下自己折 ...
 - Maven : 将Jar安装到本地仓库和Jar上传到私服 转
			
http://blog.csdn.net/we_shell/article/details/49819221 Jar的maven配置 <dependency><groupId> ...
 - 转 python 之 分割参数getopt
			
python 之 分割参数getopt os下有个方法walk,非常的好用,用来生成一个generator.每次可以得到一个三元tupple,其中第一个为起始路径,第二个为起始路径下的文件夹,第三个是 ...
 - 使用val()方法设置表单中的默认选中项
			
有时候我们展示给用户的表单中的checkbox,radio,selec等标签的一些项是默认选中的.比方:当用户改动文章的时候,假设相应的栏目为下拉框的话,那么它的默认选中值应该是原来的栏目位置. 能够 ...
 - 【Oracle】OCR的备份和恢复之导出导入
			
使用导出导入进行OCR的备份和恢复: 在对集群做调整前.如:增删节点等操作前,应该对OCR进行一次备份.能够使用export备份到指定文件. 实验环境: OS:OEL5.6 RAC:10.2.0.1. ...
 - spring security3.2配置---权限管理
			
之前已经在我的博客中发过security的执行流程图了,大家能够先去看看那个图再看这篇.今天我主要在这里贴出了security配置中的几个重要的类和两个xml配置文件,基本上控制权限的就是这几个文件了 ...
 - android79 Fragment生命周期
			
切换成01时依次调用onCreate,onStart,onResume方法,切换到03的时候01依次onPause,onStop,onDestroy,03依次onCreate,onStart,onRe ...
 - IO负载高的来源定位  IO系列
			
http://elf8848.iteye.com/category/281637 前言: 在一般运维工作中经常会遇到这么一个场景,服务器的IO负载很高(iostat中的util),但是无法快速的定位到 ...
 - MYSQL 学习笔记1 -----mysqladmin -uroot -p status|extended-status
			
root@server1 ~]# mysqladmin -uroot -p status -i -r extended-status|grep Handler_commit Enter passwor ...
 - HDU2084JAVA
			
数塔 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...