This article provides insight into how to create a new user and grant appropriate privileges on a MySQL database. To put it simply, you will decide on who can do what and with what object types. By doing so, you can give permissions or introduce restrictions within the databases or certain database objects. However, once you decide to let more people access and modify your MySQL database, you need to create users and grant them privileges. When you install MySQL Server on your system and create a MySQL database, you run the required commands in the MySQL shell as root or administrative user, meaning that you have the full power to control every aspect of your database. Introductionįirst, let’s figure out why we need users and privileges. Learn the basics of user account management and find hints. You will just have to maintain its integrity.This article provides a complete overview of how to create a new user account in MySQL and grant different types of privileges on a MySQL database. Going forward, you can user with the same rights as and you have hidden the password well. This will place you at the line where the command to print the PASSWORD function from text was done. Once you enter into vi, run /SELECT PASSWORD, hit enter. Step 03) Remove the commands from the audit history of mysql.Įvery time you login to mysql, the commands are recorded in a file called. The first line SET SQL_LOG_BIN=0 simply prevents the command from being recorded in the binary logs if you have binary logging enabled. This creates the user and sets his password. GRANT ALL PRIVILEGES ON *.* to IDENTIFIED BY PASSWORD '41-character MD5-like string' Step 02) As login to mysql and run SET SQL_LOG_BIN=0 This will return a 41-character MD5-like string. Step 01) As login to mysql and run SELECT PASSWORD('creatorpassword') * TO you seriously do not want to user create the user as follows: Mysql -u$rootuser -p$rootpass -e "GRANT ALL PRIVILEGES ON $dbname. Mysql -u$rootuser -p$rootpass -rs -e "CREATE DATABASE IF NOT EXISTS $dbname " Mysql -u$rootuser -p$rootpass -rs -e "GRANT USAGE ON *.* TO IDENTIFIED BY '$dbpass' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 " Mysql -u$rootuser -p$rootpass -rs -e "CREATE USER IDENTIFIED BY '$dbpass' " With these things in mind, this is how you can create new users with its own database: rootuser=root However, it is not even necessary because the GRANT command internally performs FLUSH PRIVILEGES. Here is something additional: Only can perform FLUSH PRIVILEGES. A superuser (such as must perform the first three lines. The first three(3) lines cannot be performed by $myuser because. Look at the order of things: mysql -u$myuser -p$mypass -rs -e "CREATE USER IDENTIFIED BY '$dbpass' " The problem here is very straightforward. So, what privilege is 'creator' missing ? I want him to have as minimal privileges as possible. When I login as 'creator', i get same errors which is odd since 'creator' has GRANT privilege. I get ERROR 1044 (42000) at line 1: Access denied for user to database 'newdb'. * TO -u$myuser -p$mypass -rs -e "FLUSH PRIVILEGES " Mysql -u$myuser -p$mypass -rs -e "GRANT ALL PRIVILEGES ON $dbname. Mysql -u$myuser -p$mypass -rs -e "CREATE DATABASE IF NOT EXISTS $dbname " * TO IDENTIFIED BY '$dbpass' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 " Mysql -u$myuser -p$mypass -rs -e "GRANT USAGE ON *. Mysql -u$myuser -p$mypass -rs -e "CREATE USER IDENTIFIED BY '$dbpass' " Script looks something like this: myuser=creator I gave him INSERT, SELECT, UPDATE, CREATE, CREATE USER, GRANT privileges, but I can't grant access to create a database for the new user. Since I don't want to do use mysql root account, I've created a new user (let's call him 'creator'). I am trying to write a simple shell script to create new mysql user and database for this user.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |