|
MySQL Privileges ------------------------ Ater you've installed mysql is good to change (add) a password for mysql root user (which is different from system root user. After you do that, the best practice is to add mysql users with different privileges (and not use mysql root user) for applications you will install.
To set a password for a mysql user:
#mysqladmin -u root -h hostname -password 'new_pass'
run your mysql client
#mysql -u root -p
After you've input your mysql password and are loged to your mysql client, type:
mysql> grant all privileges on *.* to 'username'@'localhost' identified by 'password' with grant option;
mysql> grant all privileges on *.* to 'username'@'%' identified by 'password' with grant option;
mysql> grant reload, process on *.* to 'admin'@'localhost';
Then you can use mysql client to connect to your mysql server, using "username" account:
#mysql -u username -h 10.0.0.1 -p
(where 10.0.0.1 is your mysql database server)
Comments: First grant rules reffers only to localhost. If you want to connect to your database server from other machines instead of localhost type the ip of your machine, or % if you want to connect from any host.
To see grants for an user use: mysql> show grants for 'username'@'localhost';
To revoke privileges from a user: mysql> revoke all privileges on *.* from 'username'@'localhost';
To see all mysql grants: mysql> show grants;
To delete a user from mysql: mysql> DROP user username;
MySQL Security: run MySQL on localhost ------------------------------------------------------- If you do not need to have access to your MySQL server from outside, you might consider to run MySQL on localhost. This can be done by editing my.cnf file (locate in /etc usualy) and adding bind-address = 127.0.0.1 to your [mysqld] section. If you cannot find my.cnf then you are running mysql with default options, you must find a my.cnf example file from your package installation files and copy it into /etc.
MySQL Database Backup / Restore -------------------------------------------
The following shows you howto backup/ restore a MySQL Database. You will need to have shell access to your mysql server or to be able to connect remotely using mysql client to your mysql server.
a) Backup your MySQL Database
#mysqldump database -p > file.sql
b) Restore your MySQL Database
#mysql -u username -p mysql> \. file.sql
First go to your mysql client then type \. file.sql You should be in the same directory as your file.sql file. If not, then use file.sql with absolute path to it. (for example if your file is located in /home/john/database, and the file name is file.sql, then the yo shoud use instead of file.sql, /home/john/database/file.sql
|