CyberKeeda In Social Media
Showing posts with label MySQL. Show all posts
Showing posts with label MySQL. Show all posts
ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key constraint
Reason - It’s because we have tried to update a table without a WHERE that uses a KEY column.
Fix - The quickest fix is to simply add SET SQL_SAFE_UPDATES=0; before your query
or execute the query before your truncate query
Use the below mentioned commands within your db to fix it.
SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE table1;TRUNCATE table2;Once records has been removed , revert the changes.
SET FOREIGN_KEY_CHECKS = 1;
Bash - Insert data in mysql table from a file using LOAD DATA LOCAL INFILE command.
As every Linux operator loves text file, a text file is enough to process anything within linux using commands.
Today, we will use the power of BASH to insert data into MYSQL table using LOAD DATA LOCAL INFILE commnad from a local text file.
Here i have some data stored into a file named as myfile.txt
Database name - mydb
Table name - mytable
filename - myfile.txt
[root@cyberkeeda ~]# mysql -uYOUR_USERNAME -pYOUR_PASS -D mydb -e "load data local infile '/tmp/myfile.txt' into table mytable fields terminated by ',' lines terminated by '\n'"
Remember for windows based system we have to add \r along with \n
# mysql -uYOUR_USERNAME -pYOUR_PASS -D mydb -e "load data local infile '/tmp/myfile.txt' into table mytable fields terminated by ',' lines terminated by '\r\n'"
Labels:
#!/bin/bash,
BASH,
Database,
MySQL
FIX - Another MySQL daemon already running with the same unix socket.
To start the MySQL service, you can remove
'/var/lib/mysql/mysql.sock'
and start the MySQL service again:- Remove the socket file:
[root@server ~]# rm /var/lib/mysql/mysql.sock rm: remove socket `/var/lib/mysql/mysql.sock'? yes
- Start the MySQL service:
[root@server~]# service mysqld start Starting mysqld: [ OK ]
Subscribe to:
Posts (Atom)