How do I create an empty database in MySQL?
8:46 PM
To create a database in MySQL and be able to access it you need to run a few commands:
Create the Actual Database
- Login into the MySQL as root or as appropriate:
- mysql -uroot -p -h localhost
- This logs into the localhost using root as the username and being prompted for the password
- Run the actual database create command:
- CREATE DATABASE database_name;
NOTE - If customer has not provided any information about schema then character set will be set to default. Default character set is Latin-1.
OR - CREATE DATABASE database_name DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
NOTE - Please cross check with customer while creating new database. I have taken the example of utf8 here. - You can check the existing character set/schema by typing following command
mysql> show create database database_name\G or mysql> show create schema database_name\G
- CREATE DATABASE database_name;
Assign a MySQL User to Connect to MySQL
- Login into MySQL as noted above
- Grant privileges to a MySQL use to login into the database
- GRANT ALL PRIVILEGES on dbname.* to 'username'@ipaddress;
NOTE - This will grant full privileges for the specified user to hit in this case the IP Address "from" the server its coming from remotely; Alternate rights can also be granted if the user is to be read only or have limited rights to do database actions.
- GRANT ALL PRIVILEGES on dbname.* to 'username'@ipaddress;
0 comments