Wednesday, March 30, 2016

Install and Run MySQL on CentOS

To install mysql run the following command:

```bash
`yum install mysql
`rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
`yum -y install mysql-community-server

Run the following command to start mysql:

`bash
`service mysql start

Run the following command to enable mysql on VM restart:

`bash
`chkconfig --levels 235 mysql on

Run the following command to access mysql

```bash
`mysql -u root

To configure myql for security run the following command:

```bash
`/usr/bin/mysql_secure_installation
Set root password? [Y/n] Y
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] n
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

Run the following command to restart mysql

```bash
`systemctl restart mysql.service

After the above steps "mysql -u root" will no longer be able to access mysql, Use the following command instead:

```bash
`mysql -u root -p mysql

To allow java applications to access mysql from another computer, run the following query and then restart mysql:

> update user set host="%" where user="root" and host='localhost';

Furthermore, ports may be blocked by firewalld running in the VM that runs the myql, which will block access by java application from another computer, this can be
resolved by stopping and disabling firewalld:

```bash
`systemctl stop firewalld.service
`systemctl disable firewalld.service

No comments:

Post a Comment