0% found this document useful (0 votes)
25 views

Select Version, Current - Date : Create A Mysql Database

The document provides instructions for connecting to a MySQL database from the mysql prompt, checking the current version and date, creating a database and user, granting privileges to the user, and exiting the mysql prompt. It also discusses setting the mysql root password and using mysqladmin as alternatives to the commands shown.

Uploaded by

Shalini Munogee
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Select Version, Current - Date : Create A Mysql Database

The document provides instructions for connecting to a MySQL database from the mysql prompt, checking the current version and date, creating a database and user, granting privileges to the user, and exiting the mysql prompt. It also discusses setting the mysql root password and using mysqladmin as alternatives to the commands shown.

Uploaded by

Shalini Munogee
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

mysql> SELECT VERSION(), CURRENT_DATE; +--------------+--------------+ | VERSION() | CURRENT_DATE | | +--------------+--------------+ | 5.5.0-m2-log | 2009-05-04 1 row in set (0.

01 sec) mysql> +--------------+--------------+

mysql> SELECT -> USER() -> , -> CURRENT_DATE;

mysql> SELECT -> USER() -> \c mysql>

mysql> SELECT * FROM my_table WHERE name = 'Smith AND age < 30; '> '\c mysql>

Note: If you have already set a password for the mysql root, you will need to use:
mysql -u root -p

(Did you forget the mysql-root password? See MysqlPasswordReset.)

Create a mysql database


mysql> CREATE DATABASE database1;

Create a mysql user

For creating a new user with all privileges (use only for troubleshooting), at mysql prompt type:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'yourusername'@'localhost' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;

For creating a new user with fewer privileges (should work for most web applications) which can only use the database named "database1", at mysql prompt type:
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON database1.* TO 'yourusername'@'localhost' IDENTIFIED BY 'yourpassword';

yourusername and yourpassword can be anything you like. database1 is the name of the database the user gets access to. localhost is the location which gets access to your database. You can change it to '%' (or to hostnames or ip addresses) to allow connections from every location (or only from specific locations) to the database. Note, that this can be a security problem and should only be used for testing purposes! To exit the mysql prompt type:
mysql> \q

Since the mysql root password is now set, if you need to use mysql again (as the mysql root), you will need to use:
mysql -u root -p

and then enter the password at the prompt.

Backup-Settings
Please, let's say something in which directories mysql stores the database information and how to configure a backup

Alternatively
There is more than just one way to set the mysql root password and create a database. For example mysqladmin can be used:
mysqladmin -u root -p password yourpassword

and
mysqladmin -u root -p create database1

mysqladmin is a command-line tool provided by the default LAMP install.


mysql> SELECT SQL_CALC_FOUND_ROWS * FROM tbl_name -> WHERE id > 100 LIMIT 10; mysql> SELECT FOUND_ROWS();

You might also like