Creating and Selecting a Database

5 (100%) 2 votes

Creating and Selecting a Database

If the database administrator creates your database for you when setting up your permissions, you can begin using it. Otherwise, you need to create it yourself:

mysql> CREATE DATABASE test2;

  • Under Unix, database names are case-sensitive (unlike SQL keywords), so you must always refer to your database as test2, not as Test2, TEST2, or some other variant.
  • This is also true for table names. (Under Windows, this restriction does not apply, although you must refer to databases and tables using the same lettercase throughout a given query.
  • However, for a variety of reasons, the recommended best practice is always to use the same lettercase that was used when the database was created.)

If you get an error such as ERROR 1044 (42000): Access denied for user ‘micah’@’localhost’ to database ‘test2’ when attempting to create a database, this means that your user account does not have the necessary privileges to do so. Discuss this with the administrator

  • Creating a database does not select it for use; you must do that explicitly.
  • To make test2 as the current database, use this statement:

mysql> USE test2;

Database changed

  • Your database needs to be created only once, but you must select it for use each time you begin a mysql session.
  • You can do this by issuing a USE statement as shown in the above example.

 

For any query or issue, feel free to discuss on http://discuss.eduguru.in
%d bloggers like this: