Thursday, November 22, 2007

Create user in MySQL

(Ref: http://dev.mysql.com/doc/mysql/en/default-privileges.html)

1. Secure root user account
shell> mysql –u root
mysql> SET PASSWORD FOR 'root'@localhost=PASSWORD('mypass');

2. Create app database and user.
shell> mysql --user=root --password=mypass mysql
mysql> create database mydb;
mysql> GRANT ALL PRIVILEGES ON mydb.* TO 'myuser'@'localhost' IDENTIFIED BY 'mypass2' WITH GRANT OPTION;
mysql> GRANT ALL PRIVILEGES ON mydb.* TO 'myuser'@'%' IDENTIFIED BY 'mypass2' WITH GRANT OPTION;

3. Backup database.
mysqldump -u root -pmypass --complete-insert=TRUE -x mydb > mydb.sql

No comments: