HowTo GRANT privileges to a Mysql user from the command line? This can be done by logging to the server via SSH. Once you are logged in, goto the Mysql prompt with the mysql user and password.
# mysql -uroot -p<mysql-pass-here>
Once at the prompt, create a database:
mysql> create database dbname;
The database with ‘dbname’ has been created. Now we need to create a user who will have access to the database. This can be done by granting privileges using ‘grant’ command
mysql> grant all on dbname.* to 'dbuser'@'localhost' identified \
by 'password';
The user ‘dbuser’ will now have access to database ‘dbname’ using the password ‘password’. This user can access only from the local server and not from external machine.
To allow user to access the database remotely, say from IP 1.2.3.4, execute:
mysql> grant all on dbname.* to 'dbuser'@'1.2.3.4' identified \
by 'password';
Using the above command, you can grant privileges to multiple users to access a database.
Comments are closed.