Sunday 26 January 2014

mysql Notes1

mysql Notes1:

001. To Login to mysql: By default there is no username and password require for normal login:
$ mysql [ This will give you the mysql prompt like: mysql> ]
$ mysql -u mysql [ login as mysql user, by default mysql user don't have any password ]

002. To list the databases;
$ show databases;
NOTE: Every mysql command need to finish with ; or with \G
NOTE: [ This will list the databases on your DataBase Management System -> DBMS ]


003. Log in as mysql root user:
$ mysql -u root

004. To change the root password: [ By default root don't have password. ] [ Login to mysql, first. ]
mysql> UPDATE mysql.user SET Password = PASSWORD('fooBar') WHERE User = 'root';
mysql> FLUSH PRIVILEGES;
NOTE:
a. mysql is the database name and user is the table where the user's informations are there.
b. PASSWORD is the function that encript the password.
c. There are more then one root by default: [ localhost, hostname and so on... like ipv4 and like that. ]
d. FLUSH PRIVILEGES [ To read the mysql permission. ]

005. Creating a user:
mysql> CREATE USER username@Hostname
mysql> CREATE USER apache@localhost;
mysql> CREATE USER rootBackup@localhost;
NOTE: This will allow that user only from that Host.

006. Granting the access:
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, FILE, INDEX, ALTER, CREATE TEMPORARY TABLES, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EXECUTE ON *.* TO apache@localhost;
mysql> GRANT ALL ON *.* TO rootBackup@localhost WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;

007. Now setting the password:
mysql> UPDATE mysql.user SET Password = PASSWORD('fooBar') WHERE user = 'apache';
mysql> UPDATE mysql.user SET Password = PASSWORD('fooBar') WHERE user = 'rootBackup';



No comments:

Post a Comment