How to reinstall MySQL database on CentOS

1, Stop MySQL server

 /etc/init.d/mysqld stop

2, Backup your databases.

cp /database_dir/database_files /backup_dir/.

3,  Remove Old MySQL files

yum remove mysql

4, Reinstall database

yum install mysql-server mysql

5, start database

/etc/init.d/mysqld start

6, create new users

 

mysql –user=root mysql -p
Enter password:

 

mysql> GRANT ALL PRIVILEGES ON *.* TO ‘admin_user’@'%my_IP_address’ IDENTIFIED BY ‘only_FBI_knows’ WITH GRANT OPTION;

mysql> quit;

/etc/init.d/mysqld stop

7, edit my.cnf file

 

    datadir=/disk2/mysql_data

 

copy files to data directory

 cp -R /var/lib/mysql/* /disk2/mysql_data/.
 cp -R /backup_dir/* /disk2/mysql_data/.
 chown -R mysql:mysql  /disk2/mysql_data

8, restart mysql

/etc/init.d/mysqld start
or
/sbin/service mysqld start

9, Import backup data

mysql -p -h localhost labsupply < labsupply.sql

 

data  backup command: 
/usr/bin/mysqldump -u root –password=topsecret –databases labsupply > labsupply.sql

 

10, Make sure MySQL will be started on reboot:

chkconfig mysqld on

posted @ 2014-03-16 20:59  Duke.Cheng  阅读(163)  评论(0)    收藏  举报