How to Start MySQL Server

Start up MySQL server .

  1. Run /etc/init.d/mysql script , which is called when system start up or shut down. It calls “mysqld_safe” when start up mysqld server.

Usage: mysql  {start|stop|restart|reload|force-reload|status}  [ MySQL server options ]

# find /etc/ -name *mysql* -exec ls {} -ltr \;
-rw-r--r--. 1 root root 844 Jan 30 00:55 /etc/logrotate.d/mysql
-rw-r--r--. 1 root root 2135 Jan 29 2014 /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
-rwxr-xr-x. 1 root root 10880 Mar 24 16:37 /etc/rc.d/init.d/mysql.server
-rwxr-xr-x. 1 root root 10815 Jan 30 00:55 /etc/rc.d/init.d/mysql
lrwxrwxrwx. 1 root root 15 Mar 24 23:31 /etc/rc.d/rc0.d/K36mysql -> ../init.d/mysql
lrwxrwxrwx. 1 root root 15 Mar 24 23:31 /etc/rc.d/rc1.d/K36mysql -> ../init.d/mysql
lrwxrwxrwx. 1 root root 15 Mar 24 23:31 /etc/rc.d/rc2.d/S64mysql -> ../init.d/mysql
lrwxrwxrwx. 1 root root 15 Mar 24 23:31 /etc/rc.d/rc3.d/S64mysql -> ../init.d/mysql
lrwxrwxrwx. 1 root root 15 Mar 24 23:31 /etc/rc.d/rc4.d/S64mysql -> ../init.d/mysql
lrwxrwxrwx. 1 root root 15 Mar 24 23:31 /etc/rc.d/rc5.d/S64mysql -> ../init.d/mysql
lrwxrwxrwx. 1 root root 15 Mar 24 23:31 /etc/rc.d/rc6.d/K36mysql -> ../init.d/mysql
-rw-r--r--. 1 root root 10168 Mar 1 04:18 /etc/selinux/targeted/modules/active/modules/mysql.pp
-rw-r--r--. 1 root root 10168 Mar 1 04:47 /etc/selinux/targeted/modules/tmp/modules/mysql.pp
-rw-r--r--. 1 root root 1060 Jan 29 2014 /etc/yum.repos.d/mysql-community-source.repo
-rw-r--r--. 1 root root 1209 Mar 24 14:43 /etc/yum.repos.d/mysql-community.repo

2) Run /etc/init.d/mysql.server, which is same as /etc/init.d/mysql. Check and adjust the hard coded directories.

3) run “bin/mysqld_safe –user=mysql &”

#bin/mysqld_safe --user=mysql &"

MySQL server be run using an unprivileged (non-root) login account. To ensure this if you run mysqld_safe as root, include the –user option as shown. Otherwise, execute the program while logged in as mysql, in which case you can omit the –user option from the command.

 4) Run mysqld directly.

# /sbin/mysqld  --user=mysql &

5) Run service.

# service mysqld start|stop|status

How to Install MySQL onto Linux Using MySQL Yum Repository

Install MySQL by Using MySQL Yum Repository

1) Update libaio to date because MySQL is depended on libaio.

[root@racnode1 ~]# yum install libaio
Loaded plugins: langpacks
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
adobe-linux-x86_64 | 951 B 00:00:00 
ol7_UEKR3 | 1.2 kB 00:00:00 
ol7_latest | 1.4 kB 00:00:00 
(1/5): adobe-linux-x86_64/primary | 1.2 kB 00:00:01 
(2/5): ol7_UEKR3/x86_64/updateinfo | 29 kB 00:00:01 
(3/5): ol7_latest/x86_64/updateinfo | 349 kB 00:00:03 
(4/5): ol7_UEKR3/x86_64/primary | 6.5 MB 00:00:26 
(5/5): ol7_latest/x86_64/primary | 8.4 MB 00:00:32 
adobe-linux-x86_64 2/2
ol7_UEKR3 158/158
ol7_latest 9212/9212
Package libaio-0.3.109-12.el7.x86_64 already installed and latest version
Nothing to do

2) Go to “Download MySQL Yum Repository” to download the release package for Linux 7 “mysql-community-release-el7-5.noarch.rpm”.

3) Install the downloaded release package.

[root@racnode1 Patches]# yum localinstall mysql-community-release-el7-5.noarch.rpm
Loaded plugins: langpacks
Examining mysql-community-release-el7-5.noarch.rpm: mysql-community-release-el7-5.noarch
Marking mysql-community-release-el7-5.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-release.noarch 0:el7-5 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
======================================================================================================================================================
 Package Arch Version Repository Size
======================================================================================================================================================
Installing:
 mysql-community-release noarch el7-5 /mysql-community-release-el7-5.noarch 4.3 k
Transaction Summary
======================================================================================================================================================
Install 1 Package
Total size: 4.3 k
Installed size: 4.3 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
 Installing : mysql-community-release-el7-5.noarch 1/1 
 Verifying : mysql-community-release-el7-5.noarch 1/1

Installed:
 mysql-community-release.noarch 0:el7-5

Complete!
[root@racnode1 Patches]#

You can check that the MySQL Yum repository has been successfully added by the following command:

[root@racnode1 Patches]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community 13
mysql-tools-community/x86_64 MySQL Tools Community 15
mysql56-community/x86_64 MySQL 5.6 Community Server 124

4) Installing MySQL with Yum.

# sudo yum install mysql-community-server
This installs the package for MySQL server (mysql-community-server) and also packages for the components required to run the server, including:

  • packages for the client (mysql-community-client)
  • the common error messages and character sets for client and server (mysql-community-common)
  • the shared client libraries (mysql-community-libs)
[root@racnode1 Patches]# yum install mysql-community-server
Loaded plugins: langpacks
Resolving Dependencies
--> Running transaction check
---> Package mariadb-server.x86_64 1:5.5.41-2.el7_0 will be obsoleted
--> Processing Dependency: mariadb-server for package: akonadi-mysql-1.9.2-4.el7.x86_64
---> Package mysql-community-server.x86_64 0:5.6.23-3.el7 will be obsoleting
--> Processing Dependency: mysql-community-common(x86-64) = 5.6.23-3.el7 for package: mysql-community-server-5.6.23-3.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) = 5.6.23-3.el7 for package: mysql-community-server-5.6.23-3.el7.x86_64
--> Running transaction check
---> Package akonadi-mysql.x86_64 0:1.9.2-4.el7 will be updated
---> Package akonadi-mysql.x86_64 0:1.9.2-4.0.1.el7 will be an update
--> Processing Dependency: akonadi(x86-64) = 1.9.2-4.0.1.el7 for package: akonadi-mysql-1.9.2-4.0.1.el7.x86_64
---> Package mariadb.x86_64 1:5.5.41-2.el7_0 will be obsoleted
---> Package mysql-community-client.x86_64 0:5.6.23-3.el7 will be obsoleting
--> Processing Dependency: mysql-community-libs(x86-64) = 5.6.23-3.el7 for package: mysql-community-client-5.6.23-3.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.6.23-3.el7 will be installed
--> Running transaction check
---> Package akonadi.x86_64 0:1.9.2-4.el7 will be updated
---> Package akonadi.x86_64 0:1.9.2-4.0.1.el7 will be an update
---> Package mariadb-libs.x86_64 1:5.5.41-2.el7_0 will be obsoleted
---> Package mysql-community-libs.x86_64 0:5.6.23-3.el7 will be obsoleting
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================================================================
 Package Arch Version Repository Size
======================================================================================================================================================
Installing:
 mysql-community-client x86_64 5.6.23-3.el7 mysql56-community 19 M
 replacing mariadb.x86_64 1:5.5.41-2.el7_0
 mysql-community-libs x86_64 5.6.23-3.el7 mysql56-community 2.0 M
 replacing mariadb-libs.x86_64 1:5.5.41-2.el7_0
 mysql-community-server x86_64 5.6.23-3.el7 mysql56-community 57 M
 replacing mariadb-server.x86_64 1:5.5.41-2.el7_0
Installing for dependencies:
 mysql-community-common x86_64 5.6.23-3.el7 mysql56-community 256 k
Updating for dependencies:
 akonadi x86_64 1.9.2-4.0.1.el7 ol7_latest 724 k
 akonadi-mysql x86_64 1.9.2-4.0.1.el7 ol7_latest 15 k

Transaction Summary
======================================================================================================================================================
Install 3 Packages (+1 Dependent package)
Upgrade ( 2 Dependent packages)

Total download size: 79 M
Is this ok [y/d/N]: y
Downloading packages:
No Presto metadata available for ol7_latest
(1/6): akonadi-mysql-1.9.2-4.0.1.el7.x86_64.rpm | 15 kB 00:00:02 
warning: /var/cache/yum/x86_64/7Server/mysql56-community/packages/mysql-community-common-5.6.23-3.el7.x86_64.rpm: V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Public key for mysql-community-common-5.6.23-3.el7.x86_64.rpm is not installed
(2/6): mysql-community-common-5.6.23-3.el7.x86_64.rpm | 256 kB 00:00:02 
(3/6): akonadi-1.9.2-4.0.1.el7.x86_64.rpm | 724 kB 00:00:03 
(4/6): mysql-community-libs-5.6.23-3.el7.x86_64.rpm | 2.0 MB 00:00:05 
(5/6): mysql-community-client-5.6.23-3.el7.x86_64.rpm | 19 MB 00:00:54 
(6/6): mysql-community-server-5.6.23-3.el7.x86_64.rpm | 57 MB 00:01:43 
------------------------------------------------------------------------------------------------------------------------------------------------------
Total 722 kB/s | 79 MB 00:01:52 
Retrieving key from file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
 Userid : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
 Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
 Package : mysql-community-release-el7-5.noarch (@/mysql-community-release-el7-5.noarch)
 From : file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
 Installing : mysql-community-common-5.6.23-3.el7.x86_64 1/11 
 Installing : mysql-community-libs-5.6.23-3.el7.x86_64 2/11 
 Installing : mysql-community-client-5.6.23-3.el7.x86_64 3/11 
 Installing : mysql-community-server-5.6.23-3.el7.x86_64 4/11 
 Updating : akonadi-1.9.2-4.0.1.el7.x86_64 5/11 
 Updating : akonadi-mysql-1.9.2-4.0.1.el7.x86_64 6/11 
 Cleanup : akonadi-mysql-1.9.2-4.el7.x86_64 7/11 
 Erasing : 1:mariadb-server-5.5.41-2.el7_0.x86_64 8/11 
 Erasing : 1:mariadb-5.5.41-2.el7_0.x86_64 9/11 
 Erasing : 1:mariadb-libs-5.5.41-2.el7_0.x86_64 10/11 
 Cleanup : akonadi-1.9.2-4.el7.x86_64 11/11 
 Verifying : mysql-community-server-5.6.23-3.el7.x86_64 1/11 
 Verifying : mysql-community-client-5.6.23-3.el7.x86_64 2/11 
 Verifying : akonadi-1.9.2-4.0.1.el7.x86_64 3/11 
 Verifying : mysql-community-libs-5.6.23-3.el7.x86_64 4/11 
 Verifying : mysql-community-common-5.6.23-3.el7.x86_64 5/11 
 Verifying : akonadi-mysql-1.9.2-4.0.1.el7.x86_64 6/11 
 Verifying : 1:mariadb-5.5.41-2.el7_0.x86_64 7/11 
 Verifying : akonadi-1.9.2-4.el7.x86_64 8/11 
 Verifying : akonadi-mysql-1.9.2-4.el7.x86_64 9/11 
 Verifying : 1:mariadb-server-5.5.41-2.el7_0.x86_64 10/11 
 Verifying : 1:mariadb-libs-5.5.41-2.el7_0.x86_64 11/11 

Installed:
 mysql-community-client.x86_64 0:5.6.23-3.el7 mysql-community-libs.x86_64 0:5.6.23-3.el7 mysql-community-server.x86_64 0:5.6.23-3.el7 

Dependency Installed:
 mysql-community-common.x86_64 0:5.6.23-3.el7 

Dependency Updated:
 akonadi.x86_64 0:1.9.2-4.0.1.el7 akonadi-mysql.x86_64 0:1.9.2-4.0.1.el7 

Replaced:
 mariadb.x86_64 1:5.5.41-2.el7_0 mariadb-libs.x86_64 1:5.5.41-2.el7_0 mariadb-server.x86_64 1:5.5.41-2.el7_0 

Complete!
[root@racnode1 Patches]#

5) Start and Stop MySQL Server.

[root@racnode1 Patches]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
mysqld.service - MySQL Community Server
 Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled)
 Active: inactive (dead)

Redirecting to /bin/systemctl start mysqld.service

[root@racnode1 Patches]# service mysqld status

Redirecting to /bin/systemctl status mysqld.service
mysqld.service - MySQL Community Server
 Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled)
 Active: active (running) since Sun 2015-03-22 15:24:56 AEDT; 13s ago
 Process: 22242 ExecStartPost=/usr/bin/mysql-systemd-start post (code=exited, status=0/SUCCESS)
 Process: 22181 ExecStartPre=/usr/bin/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 22241 (mysqld_safe)
 CGroup: /system.slice/mysqld.service
 ├─22241 /bin/sh /usr/bin/mysqld_safe
 └─22390 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mysqld.log --...

Mar 22 15:24:54 racnode1 mysql-systemd-start[22181]: Support MySQL by buying support/licenses at http://shop.mysql.com
Mar 22 15:24:54 racnode1 mysql-systemd-start[22181]: Note: new default config file not created.
Mar 22 15:24:54 racnode1 mysql-systemd-start[22181]: Please make sure your config file is current
Mar 22 15:24:54 racnode1 mysql-systemd-start[22181]: WARNING: Default config file /etc/my.cnf exists on the system
Mar 22 15:24:54 racnode1 mysql-systemd-start[22181]: This file will be read by default by the MySQL server
Mar 22 15:24:54 racnode1 mysql-systemd-start[22181]: If you do not want to use this, either remove it, or use the
Mar 22 15:24:54 racnode1 mysql-systemd-start[22181]: --defaults-file argument to mysqld_safe when starting the server
Mar 22 15:24:55 racnode1 mysqld_safe[22241]: 150322 15:24:55 mysqld_safe Logging to '/var/log/mysqld.log'.
Mar 22 15:24:55 racnode1 mysqld_safe[22241]: 150322 15:24:55 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Mar 22 15:24:56 racnode1 systemd[1]:Started MySQL Community Server


[root@racnode1 Patches]# service mysqld stop

Redirecting to /bin/systemctl stop mysqld.service
[root@racnode1 Patches]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
mysqld.service - MySQL Community Server
 Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled)
 Active: inactive (dead) since Sun 2015-03-22 15:27:37 AEDT; 5s ago
 Process: 22242 ExecStartPost=/usr/bin/mysql-systemd-start post (code=exited, status=0/SUCCESS)
 Process: 22241 ExecStart=/usr/bin/mysqld_safe (code=exited, status=0/SUCCESS)
 Process: 22181 ExecStartPre=/usr/bin/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 22241 (code=exited, status=0/SUCCESS)

Mar 22 15:24:54 racnode1 mysql-systemd-start[22181]: WARNING: Default config file /etc/my.cnf exists on the system
Mar 22 15:24:54 racnode1 mysql-systemd-start[22181]: This file will be read by default by the MySQL server
Mar 22 15:24:54 racnode1 mysql-systemd-start[22181]: If you do not want to use this, either remove it, or use the
Mar 22 15:24:54 racnode1 mysql-systemd-start[22181]: --defaults-file argument to mysqld_safe when starting the server
Mar 22 15:24:55 racnode1 mysqld_safe[22241]: 150322 15:24:55 mysqld_safe Logging to '/var/log/mysqld.log'.
Mar 22 15:24:55 racnode1 mysqld_safe[22241]: 150322 15:24:55 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Mar 22 15:24:56 racnode1 systemd[1]: Started MySQL Community Server.
Mar 22 15:27:36 racnode1 systemd[1]: Stopping MySQL Community Server...
Mar 22 15:27:37 racnode1 mysqld_safe[22241]: 150322 15:27:37 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
Mar 22 15:27:37 racnode1 systemd[1]: Stopped MySQL Community Server.
[root@racnode1 Patches]#