Good Day..
As per the ansible documentation, I can not find MySQL related tasks for Wondows machine.
I need to create manual tasks to perform automated tasks for windows machine.
I have performed these tasks successfully
- name: Install mysql-connector
win_chocolatey:
name: mysql-connector
version: '8.0.28'
state: present
- name: Connection
raw: mysql -h localhost --user=root --password= --execute "CREATE DATABASE testDB"
This tasks installs mysql and creates database named testDB in my virtual windows machine.
Now I want to create table inside that database. I have tried 2 ways. both are having issues for me
1.
- name: Create Table
raw : mysql -h localhost --user=root --password= --execute "CREATE TABLE `testDB`.`test1` (`employeeName` VARCHAR(20) NULL,`email` VARCHAR(45) NULL);"
-- Here, ` sign is behaving odd.
Error: Unknown database 'estDB'\r\n", // It is omitting first character from testDB
2.
I am trying to use dumped .sql file and want to import it directly. So that it can import DB with tables and fields.
- name: Table creation1
raw: mysql -h localhost --user=root --password= --execute "test < teamManagementApp.sql"
But here, < this character shows as reserved character for windows machine
Can someone help here?
Related
I have 29GB magento db .sql file that need to be imported into mysql database, I am using Ubuntu 22.04 operating system
I import into database using command line as below
mysql -u root -p
mysql > USE magento_project1
mysql > source db_dump.sql
The import seems to be working fine at first, but after a few hours of importing error as below comes out
ERROR at line 44259: ASCII '\0' appeard in the statement, but this is not alllowed unless option --binary-mode is enabled and mysql is run in non-interactive mode. Set --binary-mode to 1 if ASCII '\0' is expected. Query: '
Attached the image of the error
I noticed the query stopped when at the part it need to insert data into sales_order_payment table
I have try
rename the db_dump.sql file to db_dump.sql.gz
based on solution given here
import using command mysql -u root -p -f -D database_name < db_dump.sql.gz
when create database, create charset as utf8mb4, collation utf8mb4_general_ci
import using command mysql -u root -p -h localhost -D database_name --binary-mode -o < db_dump.sql
based on solution given here
When i write command file db_dump.sql.gz I get the result as below
db_dump.sql.gz: ASCII text, with very long lines (37268)
My ubuntu is already sudo apt-update and sudo apt-upgrade with mysql, php, nginx and elasticsearch installed and enabled
But none of the solution above fix the issue I am having
Able to fix the issue by dumping new database from magento cloud using command below
magento-cloud db:dump
0 -> Staging -> 0 ( database )
then import the db into local using command below
mysql -u root -p -f -D local_db < dumped_db.sql
Not sure what cause the error above on the first place, might be the db corrupted somewhere during transfer between pendrive ?
We have quite large (about 1TB) MySQL 5.7 DB, hosted on RDS. We want to migrate it to Aurora 5.6 - because of parallel queries (these are available only for 5.6).
It's not possible to do that by snapshot, because the version is not the same. We need to do mysqldump and then restore it.
I tried several options, but most of them always failed, because of the size of DB.
For example straight import
nohup mysqldump -h fmysql_5_7host.amazonaws.com -u user -pPass db_name | mysql -u user2 -pPAss2 -h aurora_5_6.amazonaws.com db_name
error in nohup.out :
mysqldump: Error 2013: Lost connection to MySQL server during query when dumping table
Also dump to s3 file failed
nohup mysqldump -h mysql_5_7host.amazonaws.com -u user -pPAss db_name | aws s3 cp - s3://bucket/db-dump.sql
error:
An error occurred (InvalidArgument) when calling the UploadPart operation: Part number must be an integer between 1 and 10000, inclusive
Both of previous methods worked for me on smaller DB, about 10GB, but not on 1TB.
Is there any other way how to migrate such database?
Many thanks.
After installing mysql on ubuntu I'd like to start the mysql service with following command which will start the service and also it will create the schema and tables.
service mysql start && mysql -u root -e "CREATE DATABASE organzation; use organzation; CREATE TABLE employee(Email varchar(30) NOT NULL)"
Now suppose I have a file.sql file, how to import this file.sql while starting the mysql service.
PS: mysql -u username -p database_name < file.sql this doesn't work while starting the mysql service.
From mysql Docker:
Initializing a fresh instance
When a container is started for the first time, a new database with the specified name will be created and initialized with the provided configuration variables. Furthermore, it will execute files with extensions .sh, .sql and .sql.gz that are found in /docker-entrypoint-initdb.d. Files will be executed in alphabetical order. You can easily populate your mysql services by mounting a SQL dump into that directory and provide custom images with contributed data. SQL files will be imported by default to the database specified by the MYSQL_DATABASE variable.
You just need to put your .sql file(s) in /docker-entrypoint-initdb.d directory.
I have mysql database in one pc but now i want to do my work on another pc.It is not possible for me to write sql queries once again because it is very time consuming.What should I do ?
**Exporting MySQL database from one pc to another pc**
Open linux terminal and type following commands to open mysql terminal
mysqldump -u "username" -p databaseName > "path where we have to .sql file for exporting" databaseName.sql
e.g. mysqldump -u root -p akashgudadhe.db > /Documents/sky/akashgudadhe.sql
it will export your mysql database to your Documents/sky directory.
**Importing MySQL database from one pc to another pc**
1.Open linux terminal and type following command to open mysql terminal
mysql -u "userName" -p //Enter password for your mysql username.
e.g mysql -u root -p //hit enter key.
it will open mysql terminal.
To import any database first we have to create blank database.
create database "databaseName"; //databaseName without " " quotes
use "databaseName";
for. e.g. create database akashgudadhe;
use akashgudadhe
Importing required databases from .sql file which we have to import in our mysql database.
source "directoryFor.sqlFolder" "databaseName.sql";
for e.g. source /Documents/akashgudadhe.sql
//databaseName.sql file is the file which we want to import in our mysql database
this is what I use in MySQL console (WAMP) (no password, as it is local)
mysql> mysql -u root -p dbase < table.sql
or this
mysql> mysql -u root -p dbase < C:\path\to\table.sql
this is what I get:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'mysql
-u root -p dbase < table.sql' at line 1
what may cause this problem?
The command you're using is meant to be run outside of the mysql shell. If you just exit out of the mysql shell and enter the same command, it should work.
OK - step by step - since, if someone is not used to it, any omission may get that "someone" lost.
remote nix server:
connect to mysql cli (command line interface) using e.g. Putty - type in: mysql -u user -pyourpassword
now you are connected to MySQL server and you can use e.g. LOAD INFILE command etc.
"exit" gets you back to "-bash" so you can use, e.g. database importing - just type: mysql -u root -p hmvc < table.sql
local WAMP - (setup: WAMP2.2 - Apache2.2.21 - MySQL5.5.20)
case I: using Windows "command prompt"
change directory to the one, where your mysql resides within WAMP root, e.g.:
C:\wamp\bin\mysql\mysql5.5.20\bin
connect to mysql cli:
mysql -u user -pyourpassword
now you are in, so you can use e.g. LOAD INFILE command etc.
"exit" gets you back to "C:\wamp\bin\mysql\mysql5.5.20\bin>" so you can use, e.g. database importing:
mysql -u root -p hmvc < table.sql
etc.
case 2: using mysql cli directly
WAMP offers a link to it in its tray icon command collection
link is called: MySQL console
it calls mysql server diretly by invoking C:\wamp\bin\mysql\mysql5.5.20\bin\mysql.exe
you can use all MySQL commands right away, like e.g. LOAD INFILE
you cannot import/dump database using this console
if you try to exit, MySQL console will do just that - it will exit (window gets closed)
I hope it will you some time.