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 SuitePerl, 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的更多相关文章

  1. Installing MySQL Server on CentOS

    MySQL is an open-source relational database. For those unfamiliar with these terms, a database is wh ...

  2. 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 ...

  3. installing mysql,this may take a few minutes,hold on plz wdcp卡住解决办法

    centos6安装wdcp时make in progress卡住的解决办法 今天在一台centos6的vps上安装wdcp出现的这个问题,到安装程序滚动至下面这里时出现"卡死". ...

  4. 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 ...

  5. Installing MySQL 5.7.23 on CentOS 7

    Installing MySQL 5.7.23 on CentOS 7 1. 安装前检查 1.1 检查NUMA是否开启 NUMA为什么要咋MySQL中禁用? MySQL是单进程多线程架构数据库,当nu ...

  6. 2003-Can't connect to mysql server on localhost (10061)

    mysql数据库出现2003-Can't connect to mysql server on localhost (10061)问题 解决办法:查看wampserver服务器是否启动,如果没有启动启 ...

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

  8. 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 ...

  9. 报错:1130-host ... is not allowed to connect to this MySql server

    报错:1130-host ... is not allowed to connect to this MySql server   解决方法: 1. 改表法. 可能是你的帐号不允许从远程登陆,只能在l ...

随机推荐

  1. JSP和servlet结合案例

    [使用JSP技术实现猜数字游戏] 设计一个web app,有一个随机数字,给5次机会让客户猜测这个数字: 1)如果客户猜的数字比产生的数字值大,则提示"可惜,大了点". 2)如果客 ...

  2. jQuery基本知识体系图

    在w3school学习了jQuery,觉得看了一遍,代码敲了一遍,大概的知识点记住了,不过觉得还是把这些知识点,放到一张图上,形成自己的jQuery的知识体系.能做到,一看到jQuery,脑海就浮现j ...

  3. hibernate中持久化对象的生命周期(三态:自由态,持久态,游离态 之间的转换)

    三态的基本概念: 1,  暂时状态(Transient):也叫自由态,仅仅存在于内存中,而在数据库中没有对应数据.用new创建的对象,它没有持久化,没有处于Session中,处于此状态的对象叫暂时对象 ...

  4. MYSQL 学习笔记1 -----mysqladmin -uroot -p status|extended-status

    root@server1 ~]# mysqladmin -uroot -p status -i -r extended-status|grep Handler_commit Enter passwor ...

  5. Android(java)学习笔记176:BroadcastReceiver之 短信发送的广播接收者

    有时候,我们需要开发出来一个短信监听器,监听用户发送的短信记录,下面就是一个案例,这里同样需要使用广播机制. 下面同样是代码示例,MainActivity.java 和  activity_main. ...

  6. linux tar 压缩解压缩

    解压 .tar.bz tar zxvf file.tar.gz .tar.gz2 tar jxvf file.tar.bz2 .bz gzip -d file.bz .gz2 bzip2 -d fil ...

  7. Java Post 数据请求和接收

    这两天在做http服务端请求操作,客户端post数据到服务端后,服务端通过request.getParameter()进行请求,无法读取到数据,搜索了一下发现是因为设置为text/plain模式才导致 ...

  8. ASP.NET操作DataTable

    .创建 datatable DataTable dt=new Datable();//可以给表创建一个名字,tb .给表加个列名: dt.Columns.Add("id", typ ...

  9. C# 事件的理解

    说实话,事件弄得还是很晕,有待于以后的强化吧,下面是我对事件的一点理解 首先,参见大牛的帖子:网上大牛事件讲解 下面我来说一说事件的大致流程: 事件委托事件概述事件就是当对象或类状态发生改变时,对象或 ...

  10. Struts2,Hibernate和Spring之间的框架整合关系

    1.首先要认清,hibernate和struts没有半点关系,所以他们之间没有任何可以整合的东西.a:struts 作为中心控制器,肯定要调用一些类来完成一些逻辑.而hibernate开发中,经常使用 ...