Sunday, May 14, 2017

Install MySQL

Contents

1.  Virtual box and Vagrant

2.  Install Apache

3.  Install MySQL

4.  Install Python

5.  Hello World with Python


MySQL

We will install MySQL this time. MySQL is a famous software that is used to use database and SQL. MySQL is a free opensource software, so it is used widely in the world.

At first, we need to uninstall MariaDB that is by default installed in the Cent OS 7:

$ sudo yum remove mariadb-libs 
$ sudo rm -rf /var/lib/mysql/

Then your MariaDB is removed. We will install MySQL now.
Go to the link:  https://dev.mysql.com/downloads/repo/yum/
Note the information highlighted by red underline. We are using Cent OS 7 (Linux). Cent OS is a very similar OS to Red Hat Enterprise Linux, so we can use same MySQL as Red Hat Linux. We will download this package for our Cent OS.


But if you are using CentOS 6, you need to use the following:



Do the following commands:
For CentOS 7
$ wget https://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm 
$ sudo rpm -ivh mysql57-community-release-el7-10.noarch.rpm 
$ sudo yum install mysql-server

For CentOS6
$ wget https://dev.mysql.com/get/mysql57-community-release-el6-11.noarch.rpm
$ sudo rpm -ivh mysql57-community-release-el6-11.noarch.rpm
$ sudo yum install mysql-server


Then MySQL is installed in your virtual machine.

If you made any mistake and want to uninstall the rpm package, run the following to find the exact package name:
$ sudo rpm -qa | grep -i mysql
Then run
$ sudo rpm -e <the exact package name>
to uninstall it.

Start MySQL with this command:
(For CentOS7)
$ sudo systemctl start mysqld

(For CentOS6 or older)
$ sudo service mysqld start

To check the status of MySQL, do this command:
(For CentOS7)
$ sudo systemctl status mysqld

(For CentOS6 or older)
$ sudo service mysqld status

Register mysqld to make it start from the beginning:
(For CentOS7)
$ sudo systemctl enable mysqld

(For CentOS6 or older)
$ sudo chkconfig mysqld on

Now we will set up our MySQL that is needed when we start MySQL for the first time. Do the following command:

$ sudo grep 'temporary password' /var/log/mysqld.log

The text underlined with red is the temporary password

We have a temporary password now. Do the following:

$ sudo mysql_secure_installation

You will be asked password, so use the temporary password that we obtained just now. Every question other than it should be ok to answer yes (y). Maybe you will be asked a new password, but the new password must contain a big letter, a small letter and a special letter like "@" and it must be longer than 8 letters.

Do the following command to log into MySQL with the new password you created just now:

$ mysql -u root -p


But I think 8 letters with a big letter, a small letter and a special letter is not useful if we often login and logout. So we will change the password and the password rule. At first, we will check current password rule:

mysql> SHOW VARIABLES LIKE 'validate_password%';

The condition for password creation

Then do the following commands to change the rule:

mysql> SET GLOBAL validate_password_length=4; 
mysql> SET GLOBAL validate_password_policy=LOW;

Conditions are changed

We will define the password as "root". Do the following command:

mysql> set password for root@localhost=password('root');


Now your password for MySQL is changed to "root". User name is also "root". To quit MySQL, do the following command:

mysql> quit