08 Sep |
|
In this tutorial you will learn about MySQL security, how to use command prompt window to start MySQL server and client. How to create MySQL user,how to grant permission or revoke permission from a user. How to set password for a new user or default root user and ananimous user. How to create database and tables using Data Definition Language. MySQL is an open source database. Download it from http://dev.mysql.com/downloads/mysql/5.0.html MySQL manual downloads http://dev.mysql.com/doc/ Installation for windows is very easy. See manual. It is recomended to install MySQL in root directory. If your Windows are installed in C drive, then install MySQL in "C:\mysql" directory. After installation go to Command Prompt. Depending on Windows version, command prompt window will open in C:\windows or C:\Documents and Settings\username> directory. What ever directory is displayed in the Command Prompt window, type cd.. command to go up to root directory. In the root directory type cd mysql\bin and press enter. When you get in C:\mysql\bin directory, type: mysqld-nt( for Windows 2000, XP) or mysqld (for windows Me, 98). MySQL will be started.
MySQL by default has two anonymous user accounts and two root user accounts without password. If you do not change these accounts, every one can access your data. To fix it, login in MySQL as root user. Type:C:\mysql\bin>mysql -u root and hit enter. The following text displays.
C:\mysql\bin>mysql -u root SET password for anonymous account
mysql> SET PASSWORD FOR ''@'localhost' =PASSWORD('lexapro'); Try to login as anonymous user without password: access denied.
C:\mysql\bin>mysql Try to login as anonymous user with new password: access granted
C:\mysql\bin>mysql -plexapro SET password for root user accounts.
mysql> SET PASSWORD FOR 'root'@'localhost' =PASSWORD('aspirin'); Try to login as root user without password: access denied
C:\mysql\bin>mysql -u root Try to login as root user with new password: access granted
C:\mysql\bin>mysql -u root -paspirin mysql To create a database type: create database eshop_db; and press enter. Database is created.
mysqlgt: create database eshop_db; To create a table type the following script:
mysqlgt: create table products( Read Database Design tutorial to learn more about designing database and SQL To view all columns in products table type: SHOW COLUMNS FROM products; and press enter.
mysqlgt: SHOW COLUMNS FROM products;
| prod_number | varchar(20) | YES | | NULL | | To view all tables in eshop_db database type: SHOW TABLES FROM eshop_db; press enter.
mysqlgt: SHOW TABLES FROM eshop_db; To create a user for your database 1. Login as 'root' user:
C:\mysql\bin>mysql -u root -paspirin 2. Type: GRANT ALL PRIVILEGES ON eshop_db.* TO 'john'@'localhost' IDENTIFIED BY 'maxalt'; and press enter. New User 'john' with password 'maxalt' created.
mysqlgt: GRANT ALL PRIVILEGES ON eshop_db.* TO 'john'@'localhost' IDENTIFIED
BY 'maxalt'; Check if user john has access to the database. Type: 'exit' to exit database.
Login as a user 'john' with password 'maxalt'.
C:\mysql\bin>mysql -u root -paspirin 2. Revoke all privileges:
Access revoked. User john cannot access eshop_db database. Please read MySQL manual to learn more... If you use MySQL 5.0 and get error message like this: mysql_connect() [function.mysql-connect]: Client does not support authentication protocol requested by server; consider upgrading MySQL client in C:\Apache2\htdocs\examples\fieldsarray.php on line 10 Unable to connect Visit MySQL web site to find out how to fix it
|















Legitcode.com : All Rights Reserved