Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a MySQL user without password - needed for remote login - to be used in bash insert script?

Tags:

My requirement is to create a user for remote login but without a password. At my remote space I use a bash script to do inserts, which is something like:

for i in {1..5000}; do   mysql -h 11.40.3.169 -uUser -pPass -DDatabaseName <<<     "insert into DatabaseTableName values('$i','dummy_$i');" &   echo -n "$i  "   sleep 1   date done 

The problem is that each insert is taking almost 4 seconds, and I can not pinpoint the problem to anything but authentication at every insert. So, if I could create a user in MySQL with minimal authentication involved...Something like:

# I'm trying to remove this password GRANT ALL PRIVILEGES TO 'user'@'%' IDENTIFIED BY 'password'; 

...Anything you can suggest.

like image 621
Chirayu Avatar asked Apr 27 '11 14:04

Chirayu


People also ask

How do I create a MySQL username and password?

Step 1: Open the MySQL server by using the mysql client tool. Step 2: Enter the password for the account and press Enter. Step 3: Execute the following command to show all users in the current MySQL server. Step 4: Create a new user with the following command.

How do I grant access to a MySQL user?

To GRANT ALL privileges to a user , allowing that user full control over a specific database , use the following syntax: mysql> GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost';


2 Answers

Just remove the IDENTIFIED BY part:

GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' 

Note that remote login from anywhere without a password is a very insecure thing. You better limit the allowed IP range for this user:

GRANT ALL PRIVILEGES  ON *.* TO 'user'@'allowed_remote_machine' 
like image 108
Quassnoi Avatar answered Sep 30 '22 06:09

Quassnoi


You can do this by creating a user with a password and then placing a .my.cnf file in the home directory of the account which runs the bash script containing the following:

[mysql] user=user password=pass [mysqladmin] user=user password=pass 

This might be better than creating a user with no password.

like image 39
cbz Avatar answered Sep 30 '22 06:09

cbz