Though newer versions of Linux Operating Systems came up with GUI to help their users, Linux Commands have their own importance. One of such scenarios which I've undergone few days back is installing MySQL on Linux.
I had to work with MySQL on Linux Platform. The operating system given to me was Ubuntu 14.04 LTS. On Ubuntu, MySQL can be installed from the source with a single line command,
shell> sudo apt-get install mysql-server5.6
But I was asked to install MySQL Server 5.6.19 Commercial on the Ubuntu system. Then I downloaded it and tried to install. Though it comes with install instructions, it's difficult to understand the commands for a Windows user like me. Later surfing through internet helped me with the information from different blogs and documents. Thanking all of them, I'm compiling them in this post. In this post, I'll show you how to install MySQL Server 5.6 from a tar file downloaded.
tar means Tape Archive. It was used in older days of UNIX where files are stored on tapes.
Installing MySQL Server 5.6
Download MySQL Server 5.6 from Oracle Website. As I specified about tar file, download the tar file which is compatible to your OS (32 bit or 64 bit).
After the download gets completed, unzip it.
Open Terminal and switch to Super User account with the following command,
shell> sudo su -
Authenticate yourself by providing your password and switch to root account.
Now copy the extracted .tar file to a location like /usr/local with the following command,
shell> cp <location of the file>/<Name of the file>.tar.gz /usr/local
After doing this, create a group with name mysql and a user mysql in that group. Note that naming the group and user mysql is not a compulsion, it's a convention. You can name them anything.
shell> groupadd mysql
shell> useradd -r -g mysql mysql
Here option -r specifies that a system account is created whose password never expires. Option -g specifies the initial group to which the user belongs to. There must exist a group which is already created.
Now go the location where the tar file is copied and it has to be unzipped to carry out the remaining part of installation. Run the following commands in a sequence,
shell> cd /usr/local
This takes you to the directory /usr/local.
shell> tar zxvf <Name of the tar file>.tar.gz
This command unzips the tar file. The option zxvf means z(unzipping), x(extract), v(print file names verbosely), f(the following argument is the name of file). The tar command is used to create, modify and access files of tar archive.
shell> ln -s <Name of the folder extracted from tar> mysql
In this command, ln means link. It means a link is created between source folder and target folder. This link should be created with an option. Here the link -s specifies that a symbolic link is created between the source folder (extracted tar folder) and the target folder (mysql).
Now a target folder is created with name mysql. Open that folder,
shell> cd mysql
shell> chown -R mysql .
In the above command, chown means Change Ownership. Here the ownership of folder mysql is given to the user mysql. The option -R specifies that this user performs operations on the folder recursively. Do not forget to run the command along with dot(.) at the end.
shell> chgrp -R mysql .
In this command, chgrp means Change Group. This means the folder mysql is now changed its group to mysql. As said above, the option -R specifies that group mysql performs operations on the folder recursively. This command is said to be the sister command of chown. Do not forget to run the command along with dot(.) at the end.
shell> scripts/mysql_install_db -user=mysql
If you observe the directory mysql, there exists a file with name mysql_install_db which contains a script. To install mysql, this should be executed. In the above command, it is executed with the privileges of user mysql.
If you're installing MySQL Server on your machine for the first time, here comes an error that a library libaio1 cannot be found. You need to install this library by using the following command,
sudo apt-get install libaio1
After this library gets installed, run the previous command again which starts installing MySQL on your system.
shell> chown -R root .
This command changes the ownership of the folder to root account.
shell> chown -R mysql data
This command changes the ownership of the folder data to user mysql.
shell> bin/mysqld_safe --user=mysql &
Here mysqld is the service of mysql. The '&' at the end specifies that the command before it should be run in background. The whole command means, the service mysqld present in bin folder must be run with the user mysql in the background.
Next comes an optional command which copies configuration file to a location in /etc folder,
shell> cp support-files/mysql.server /etc/init.d/mysql.server
Now MySQL Server is installed in your system
Connecting to MySQL Server 5.6
To connect to the above installed MySQL Server,
Open Terminal and switch to root account by authenticating yourself,
shell> sudo su -
Go to the location where MySQL was installed,
shell> cd /usr/local/mysql/bin
Run the executable mysql with the command
shell> ./mysql
This takes you to mysql command line. To check, run the following query which shows the databases present in the server,
mysql> show databases;
Troubleshooting MySQL Server on Ubuntu
MySQL is easier to install on Ubuntu and annoys that much too. Sometimes when machine is restarted or under any situation, you cannot get connected to the MySQL Server installed on your machine. When you try to get connected, it shows the following error,
Can't connect to local
MySQL server through socket '/tmp/mysql.sock' (2)
This means server is not running at local machine unless you didn't do any changes in the configuration file. So, to start the service again, run the following command,
shell> sudo
/usr/local/mysql/support-files/mysql.server start
To stop the server, replace start with stop in above command,
shell> sudo /usr/local/mysql/support-files/mysql.server stop
To restart the server, replace start with restart,
shell> sudo /usr/local/mysql/support-files/mysql.server restart
Now play with your MySQL Server on Linux. Hereby I thank all the bloggers who helped me with their educative posts.
Thank you so much for throwing light on such an important topic, not sure if you are interested in 3rd party product but ZappySys has very easy solution.
ReplyDeleteLink here"
SQL Server Load Soap API