MySQL provides various methods for downloading and Installation. When you are going to install MySQL, you have to first decide which version of MySQL to use. MySQL development is available in several release types, and you can pick the one that best fits your needs according to server you are using. After deciding the suitable version for your server to install, you need to choose a distribution format. Releases are available in binary or source format.
You can download the MySQL from the following location of MySQL website:
http://dev.mysql.com/downloads/
The general MySQL package you need to download is MySQL Community Server. Under the MySQL community server you can choose your installation package according to release selected.
Installing MySQL on Windows Machine:
Installation of MySQL on windows machine is easier as compared to any other operating system as MySQL provides exe or msi files in zip folder and you need to just unzip and run the installation file and follow the instructions for setting user and password, that’s it.
Default installation filemysql-version.exe will take you through the easy process and by default will install all things under C:\mysql directory. After the installation you get desktop shortcut or a icon in Programs to start the MySQL prompt.
By default the MySQL starts automatically on start-up of the Windows. You can start, stop, restart and check the status of MySQL through services.msi in Run prompt in windows. There is no such GUI provided for MySQL. You have to use external tools or you can download MySQL workbench from the MySQL website itself.
You can get the data directory and other MySQL binary files under the C:\Program Files\MySQL directory by default. There a file is created named my.ini which contains the MySQL configuration parameters that is discussed later on further chapters.
Command to run and start MySQL on command prompt:
mysql –uroot –p
It looks like this:
C:\Users\aman.aggarwal>mysql -h localhost -u root -ppassword Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 to server version: 5.6.20 Type 'help;' or '\h' for help.Type '\c' to clear the buffer. mysql> USE mysql; mysql> SHOW TABLES; +-----------------+ | Tables_in_mysql | +-----------------+ | columns_priv | | db | | func | | host | | tables_priv | | user |
Installing MySQL on Linux/Unix Based systems
There are various formats which can be used with Linux/Unix based systems. You can install MySQL by simply yum or apt-get depending upon the flavor you are using. But the recommended way to install MySQL on LINUX is using RPM (RedHat Package Manager) packages.
Following are RPM that needs to install MySQL on the server, each serving its own purpose:
· MySQL - The MySQL server, which manages databases and tables, controls user access, and processes SQL queries.
· MySQL-client - MySQL client API, which allowsto connect and interact with the server to the user.
· MySQL-devel– All MySQL Libraries and header files are used when compiling other program that needs MySQL installation.
· MySQL-shared - Shared libraries for the MySQL client.
· MySQL-bench - Benchmark and performance testing tools for the MySQL database server. It is used during the optimization processes.
You can download all the rpm and then need to run the simple rpm install command for installing MySQL:
Rpm -i MySQL-version.rpm Rpm -i MySQL-client-version.rpm Rpm -i MySQL-devel-version.rpm Rpm -i MySQL-shared-version.rpm Rpm -i MySQL-bench-version.rpm
Manual Installation from tar binary
You can also install MySQL manually from tar binaries by specify all directory that you want to use for MySQL. Below are the basic steps for installation through tar Binary downloaded from the MySQL website.
Steps:
- Create a MySQL User and Group that is responsible for running MySQL.
shell> groupadd mysql shell> useradd -g mysql mysql
- Move the Tar file to desired location generally we move it to /usr/local although you can specify your suitable path.
shell> cd /usr/local shell> tar –zxvf mysql-VERSION-OS.tar.gz
- Change the Group and Owner of the MySQL files to mysql:mysql (user:group)
shell> chown –R mysql:mysql /usr/local/mysql shell> cd mysql
- Run script mysql_install_dbfile to create system files.
shell> scripts/mysql_install_db --user=mysql [--datadir=#datadir if you want to change the data directory to somewhere else.]
- Create a my.cnf file at the default location or provide the –-defaults-file option while starting mysqld_safe.
(my.cnf is MySQL configuration file that allow you to set various properties of MySQL server under which it can run.) shell>cp support-files/my-medium.cnf /etc/my.cnf
- Now start the MySQL server Daemon by the command: shell> bin/mysqld_safe --user=mysql &
- If you want MySQL to start automatically when you boot your machine, you can copy supportfiles/mysql.server to the location where your system has its startup files.
shell>cp support-files/mysql.server /etc/init.d/mysql (Make sure that it is executable. (‘x’ is set)) shell>chmod +x /etc/init.d/mysql
- After installing the script, the commands needed to activate it to run at system startup depend on your operating system. On Linux, you can use chkconfig: shell>chkconfig --add mysql
- On some Linux systems, the following command also seems to be necessary to fully enable the mysql script: shell>chkconfig --level 345 mysql on
- Secure the Initial MySQL installation, its an optional step to make your MySQL secure.
shell> bin/mysql_secure_installation (The MySQL server must be in running state for this step to complete.)
- For shutting down the Server, pass the following command:
shell> mysqladmin –u root –p shutdown password:<give mysql root password here, if no password then leave blank.>
- You should add the path to MySQL bin directory in the PATH environment variable by setting it in mysql user profile or by some other way. Doing so you can run client programs etc. from anywhere and no need to set current working directory again and again.
- Sample my.cnf file
[client] port=3306 socket=/tmp/mysql.sock [mysqld] basedir==/usr/local/mysql datadir=/usr/local/mysql/data socket=/var/tmp/mysql.sock port=3306 user=mysql
Post Installation Steps
MySQL needs some steps after the installation. These are not necessary but useful in terms of security in case of MySQL installation over the servers or shared locations or MySQL over the web.
The most important step is to set the password for root user as default installation has no password. This can be done in two ways:
- Using mysqladmin command as :
mysqladmin-u root password "new_password";
- Login to mysql and then set password using update command.
Shell> mysql –uroot Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 73275 Server version: 5.5.27-log Source distribution Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help.Type '\c' to clear the current input statement. mysql>update mysql.user set password = password(‘new_password’); mysql> flush privileges;
If you want to run MySQL server at boot time, then make sure you have following entry in /etc/rc.local file.
/etc/init.d/mysqld start
Delete Anonymous users created by MySQL from the following command:
DELETE FROM user WHERE User='' AND Host='localhost';