Run sql in Dockerfile starting from exisiting MySQL db image [duplicate] - mysql

This question already has answers here:
How to create populated MySQL Docker Image on build time
(6 answers)
How can I initialize a MySQL database with schema in a Docker container?
(11 answers)
Closed last month.
I am trying to build a new mysql image from an existing one, and then insert some records into the database as part of the build process to create the new image (i.e. new mysql image = old mysql image + extra table records).
I am not able to add an sql file that contains my insert queries to /docker-entrypoint-initdb.d, cause that is not executing the scripts inside that directory (because the starting image already has a /var/lib/mysql dir available?).
I have tried to do something like the following instead:
FROM my.registry/starting-mysql-img:latest
ADD insert-queries.sql /tmp
RUN mysql -u root mydb < /tmp/insert-queries.sql
But I get a
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) error.
What am I doing wrong / is there an alternative way to achieve my I am looking for?

Related

how to edit secure_file_priv using MYSQL Docker container

I created MySQL cluster of nodes (2 datanodes, 1 management node, and 1 MySQL server node) on Docker Following the instructions from this link:
https://mysqlmed.wordpress.com/2017/09/04/mysql-cluster-in-docker-quick-step-by-step
Then I created a MySQL table to import a csv file (named daily.csv) using the command:
LOAD DATA INFILE 'C:/Users/Utilisateur/Desktop/daily.csv' INTO TABLE daily IGNORE 1 LINES;
and I got the error:
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement.
When I add LOAD DATA LOCAL INFILE ..
I get this error:
ERROR 2 (HY000): File 'C:/Users/Utilisateur/Desktop/daily.csv' not found (Errcode: 2 - No such file or directory)
When i check my secure-file-priv using the command:
SELECT ##global.secure_file_priv
I get the Following path: /var/lib/mysql-files/ but I have no idea how to access to it in order to copy my csv file, or even to access my.ini MySQL config file to change the variable secure-file-priv into NULL, which as I saw is another solution to get permissions to access my file.
As I am using Docker, I have no idea how to access the MySQL container config file.
I tried many ways but I see no issue. Could you please help me with this I would be very delighted as I spent a lot of time trying to fix it??
I followed these instructions but don't know where the file /etc/mysql/my.cnf to change the variable secure_file_priv to NULL is:
Mysql making --secure-file-priv option to NULL
In your case it might be sufficient to mount your local directory inside the directory expected by mysql (/var/lib/mysql-files/).
Try starting the container with an additional -v parameter, like this:
docker run -d -v C:/Users/Utilisateur/Desktop/:/var/lib/mysql-files --net=cluster --name=mysql1 --ip=192.168.0.10 -e MYSQL_RANDOM_ROOT_PASSWORD=true mysql/mysql-cluster mysqld
Or copy the file into the folder:
docker cp C:/Users/Utilisateur/Desktop/daily.csv mysql1:/var/lib/mysql-files
assuming the name of your container is mysql1, as in the link you provided.

Is there any way to export a database using MYSQL Command Line Client? [duplicate]

This question already has answers here:
How to export a mysql database using Command Prompt?
(20 answers)
Closed 3 years ago.
Is there any way to export a MySQL database using MYSQL Command Line Client?
I have a database named as naukri_portal, which contains 3 tables. I am trying to export the database using MYSQL Command Line Client but it didn't work.
mysqldump -u root -p naukri_portal > naukri_portal.sql
you can use this command which will ask for a password and download your database into the current directory
mysqldump -u root -p database> dump.sql
if you are form windows use PowerShell administrator mode and if you are using Linux use Sudo command. Then run those query.
You can also follow below steps
Step -1 First download SQLyog https://sqlyog.jaleco.com/, then install it.
You will get something like
Now create a new connection for your localhost then connect to your remote database. You must remain connected to both servers together.
Step -2 Then right-click to your remote database you will get the following options.
step-3 Now click copy database to a different host then you will get another window like
step-4 Finally, select localhost and your database from the dropdown option. If you want structure and data check below option. Then click copy. The database will be copied. Due to my old version interface could be different but process will remain the same.

Unknown system variable when opening phpmyadmin [duplicate]

This question already has answers here:
#1193 - Unknown system variable 'lc_messages' when trying to login to phpmyadmin
(7 answers)
Closed 5 years ago.
Error
SQL query: Edit Edit
SET lc_messages = 'en_US';
MySQL said: Documentation
1193 - Unknown system variable 'lc_messages'
I had the same problem and here is how I fixed it:
Upgraded mysql to latest version: http://www.tecmint.com/install-latest-mysql-on-rhel-centos-and-fedora/
After the upgrade mysql service couldn't start. Here's the fix:
mysqld_safe --skip-grant-tables
mysql_upgrade
Go to Shell (In xampp at right corner, third one)
Enter
mysql // Hit enter
SET lc_messages = 'en_US'; //Hit enter
Restart Mysql

Accidentally dropped table from mysql server [duplicate]

This question already has answers here:
How do I restore a dump file from mysqldump?
(19 answers)
Closed 5 years ago.
I'm new to MySQL, and I accidentally dropped a table with approx 3gb worth of data. Good news, I think I have a backup file .dump. Now is there an easy way to import this file to my MySQL?
mysql -u username -p databse_name < backup.sql

Create a batch-file which executes a local saved (MY)SQL Text file [duplicate]

This question already has answers here:
Batch file to connect mysql and run commands
(3 answers)
Closed 6 years ago.
I want to create a batch-file which executes a local saved (MY)SQL Text file (sql procedure) The tables created by the execution of the sql-file will use data from a server I have access to (hostname: server1; Port: 3306, (my) username: User2 Password:I´m using no password so the password is empty, Connection Name: ConnectiontoSQLServer, Name of Schema: ABC )
->How will the command in the batch-file look like?
Thanks for your support!
I tried this now, but it´s not working:
mysql --host=server1 --port=3306 --user=User2 --password= --database=ABC < C:\Users\krohn\Documents\Arbeit\SQL Queries\Tabellen CRM-Work\Tabellenaktualisierung.sql
-> What´s wrong?
You can "execute" sql files on command line:
mysql -h server1 -u User2 < C:\Users\X\...