To insert data from bash command line you will need username and password to your MySQL database. Consider a following table called “fruits” with auto increment “id”:
Next, we have a file with some data:
$ cat /tmp/fruits
for i in $( cat /tmp/fruits ); do echo “INSERT INTO fruits (fruit) values ($i);” | mysql -u root -p password mydatabase; done
Run a command like below to access from all machines.
mysql> GRANT ALL PRIVILEGES ON *.* TO ‘USERNAME’@’%’ IDENTIFIED BY ‘PASSWORD’ WITH GRANT OPTION;
Run a command like below to give access from specific IP.
mysql> GRANT ALL PRIVILEGES ON *.* TO ‘USERNAME’@’18.104.22.168’ IDENTIFIED BY ‘PASSWORD’ WITH GRANT OPTION
run the command vim /etc/mysql/my.cnf
comment bind-address = 127.0.0.1 using the # symbol
restart your mysql server once.
In Step 1, if you cannot find bind-address in the my.cnf file, look for it in /etc/mysql/mysql.conf.d/mysqld.cnf file