I'm looking for something like createdb in PostgreSQL or any other solution that would allow me to create database with a help of a shell command. Any hints?
相关问题
- How to get the return code of a shell script in lu
- sqlyog export query result as csv
- NOT DISTINCT query in mySQL
- MySQL: conduct a basic search
- Why sometimes there is one of more gap(s) in the v
You can use SQL on the command line:
Or you can use
mysqladmin
:Connect to DB using base user:
mysql -u base_user -pbase_user_pass
And execute CREATE DATABASE, CREATE USER and GRANT PRIVILEGES Statements.Here's handy web wizard to help you with statements www.bugaco.com/helpers/create_database.html
You mean while the mysql environment?
Or directly from command line:
Use
You will be prompted for password. Also make sure the mysql user you use has privileges to create database.
If you create a new database it's good to create user with permissions only for this database (if anything goes wrong you won't compromise root user login and password). So everything together will look like this:
Where:
base_user is the name for user with all privileges (probably the root)
base_user_pass it's the password for base_user (lack of space between -p and base_user_pass is important)
new_db is name for newly created database
new_db_user is name for the new user with access only for new_db
new_db_user_pass it's the password for new_db_user
Replace above variables and you are good to go with this oneliner. $USER is the username, $PASSWORD is the password and $DB_NAME is the name of the database.