Thursday, October 1, 2009

CentOS: Install MySQL Server

To install MySQL under CentOS, login as ROOT and input:

# yum install mysql-server

To start the service:

# service mysqld restart

Which will give some message:

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h testserver1 password 'new-password'

Use mysqladmin setup the password.

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

Set mysql service automatic start after reboot:

# chkconfig --levels 35 mysqld on


Set up mysql service port:

# /sbin/service mysqld stop
# vi /etc/my.cnf
modify: port=3306
/sbin/service mysqld start

To change mysql data directory:

# mkdir /home/mysql
# chown -R mysql:mysql /home/mysql
# chcon -R -h -t mysqld_db_t /home/mysql

# service mysqld stop
# mv /var/lib/mysql/* /home/mysql
# vi /etc/my.cnf

Modify:
#datadir=/var/lib/mysql
datadir=/home/mysql

# vi /etc/init.d/mysqld

Modify:
#get_mysql_option mysqld datadir "/var/lib/mysql"
get_mysql_option mysqld datadir "/home/mysql"

# service mysqld start

Check MySQL log file:

# cat /var/log/mysqld.log

Add a new remote user:
mysql> GRANT ALL PRIVILEGES ON *.* TO admin@"%" IDENTIFIED BY 'mysql' WITH GRANT OPTION;

1 comment: