Wednesday, March 30, 2016

Install and Run MySQL on CentOS

To install mysql run the following command:

`yum install mysql
`rpm -Uvh
`yum -y install mysql-community-server

Run the following command to start mysql:

`service mysql start

Run the following command to enable mysql on VM restart:

`chkconfig --levels 235 mysql on

Run the following command to access mysql

`mysql -u root

To configure myql for security run the following command:

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

`systemctl restart mysql.service

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

`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:

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

No comments:

Post a Comment