I am very new to SQL and in fact just started yesterday. The book I am following is asking me to run sql statements from a text file they provided. However, I am getting an error message and I dont understand why. Here is the commands I entered along with the error message:
mysql> use bank;
Database changed
mysql> source c:\sql\LearningSQLExample.sql;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 9
Current database: bank
--------------
mysql Ver 14.14 Distrib 5.6.12, for Win64 (x86_64)
Connection id: 9
Current database: bank
Current user: lrngsql#localhost
SSL: Not in use
Using delimiter: ;
Server version: 5.6.12 MySQL Community Server (GPL)
Protocol version: 10
Connection: localhost via TCP/IP
Server characterset: utf8
Db characterset: utf8
Client characterset: cp850
Conn. characterset: cp850
TCP port: 3306
Uptime: 1 day 4 hours 9 min 17 sec
Threads: 1 Questions: 6474 Slow queries: 1 Opens: 111 F
tables: 79 Queries per second avg: 0.063
--------------
ERROR:
Unknown command '\L'.
ERROR:
Failed to open file 'c:ql\LearningSQLExample.sql', error: 2
Thanks for your help.
You need to escape the backslash. Type source c:\\sql\\LearningSQLExample.sql;
Just an additional solution when for newer version of mySQL command line
Rename the LearningSQLExample.sql file to something that have underscore in it.
Something like s_s.sql then at the command line try
source c:/temp/s_s.sql;
Related
Can't find out what's the actual problem. i am using the below example which works fine in:
e.g:
select * from table where (( p1 = '' OR p2 = '') OR table_column BETWEEN p1 AND p2)
Server: Localhost via UNIX socket
Server type: MariaDB
Server version: 10.0.31-MariaDB-cll-lve - MariaDB Server
Protocol version: 10
Server charset: UTF-8 Unicode (utf8)
but when i run the same query on:
Server: Localhost via UNIX socket
Server type: MySQL
Server version: 5.6.37 - MySQL Community Server (GPL)
Protocol version: 10
Server charset: UTF-8 Unicode (utf8)
it doesn't work! Any help would be appreciated.
EDIT:
p1 and p2 are parameters with the datatype YEAR and query is in a procedure.
I'm doing some MYSQL work for a company, and I need to know if they have an ENTERPRISE or COMMUNITY edition. I researched this, and according to the mysql reference pages, I should be able to use the "status" command. According to that reference, the "Server Version" should say "Community", or "enterprise". Ours says neither (figures, right?), just "5.0.77 Source Distribution". Is there another way to tell?
tl;dr
Try this:
mysql> SHOW VARIABLES LIKE "%version%";
Normal answer
Using a command client (mysql), the server version of the MySQL server to which you are connected is shown once you are connected. The server version information includes community or enterprise accordingly.
For example, here is the output from a MySQL Community Server edition installed on Linux:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.0.27-standard MySQL Community Edition - Standard (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
This is an example of the output from MySQL Enterprise Server on Windows:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.28-enterprise-gpl-nt MySQL Enterprise Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
You may also determine the version information using the version variables. Both the version and version_comment variables contain version information for the server to which you are connected. Use the SHOW VARIABLES statement to obtain the information you want, as shown in this example:
mysql> SHOW VARIABLES LIKE "%version%";
+-------------------------+------------------------------------------+
| Variable_name | Value |
+-------------------------+------------------------------------------+
| protocol_version | 10 |
| version | 5.0.27-standard |
| version_comment | MySQL Community Edition - Standard (GPL) |
| version_compile_machine | i686 |
| version_compile_os | pc-linux-gnu |
+-------------------------+------------------------------------------+
5 rows in set (0.04 sec)
Straight from the documentation.
But, of course, so is STATUS;
The STATUS command displays the version as well as version comment information. For example:
mysql> STATUS;
--------------
./client/mysql Ver 14.12 Distrib 5.0.29, for pc-linux-gnu (i686) using readline 5.0
Connection id: 8
Current database:
Current user: mc#localhost
SSL: Not in use
Current pager: /usr/bin/less
Using outfile: ''
Using delimiter: ;
Server version: 5.0.27-standard MySQL Community Edition - Standard (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: latin1
Conn. characterset: latin1
UNIX socket: /tmp/mysql.sock
Uptime: 1 day 3 hours 58 min 43 sec
Threads: 2 Questions: 17 Slow queries: 0 Opens: 11 Flush tables: 1 Open tables: 6 Queries per second avg: 0.000
--------------
So I wonder whether you're actually just looking at the first line provided or whether you're checking below for the "Server version" line.
If nothing works for you then feel free to edit your question with a complete dump of what you get.
Edit
As you found out it appears that they do not disquisition between the releases since it's a specific edition release, in this case a Community Edition. Thus the answer generally only works if you can't be certain by looking up the version.
I have created a table in MySQL and have the SQL script handy to create all the tables ans master data. However, i tried all possible way but it is not letting me to do so.
From the command prompt, i connected to mysql by passing this
>mysql -localhost -root -p;
mysql> Use MYDB
mysql> source d:\script\test.sql
it is giving me a message which i don't understand, please help.
mysql Ver 14.14 Distrib 5.6.20, for Win64 (x86_64)
Connection id: 22
Current database: oyeohdb
Current user: dms#localhost
SSL: Not in use
Using delimiter: ;
Server version: 5.6.20 MySQL Community Server (GPL)
Protocol version: 10
Connection: localhost via TCP/IP
Server characterset: latin1
Db characterset: latin1
Client characterset: cp850
Conn. characterset: cp850
TCP port: 3306
Uptime: 1 hour 13 min 34 sec
Threads: 1 Questions: 99 Slow queries: 0 Opens: 68 Flush tables: 1 Open tab
les: 61 Queries per second avg: 0.022
--------------
Outfile disabled.
ERROR:
Failed to open file 'D:criptest.sql', error: 2
mysql> SOURCE D:/script/test.sql;
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 'TYPE=
MyISAM' at line 10
mysql>
Backslash is MySQL's escape character in strings. You should either double it or use forward slash:
mysql> source d:\\script\\test.sql
mysql> d:/script/test.sql
I have had a similar issue and it was solved by running
mysql_upgrade.exe
Located at:
...bin\mysql\mysql5.6.17\bin
I hope that this issue works out for you. Cheers!
I am having a baffling problem with a simple RDS read replica, where when we do a LOAD DATA LOCAL INFILE on the master, it kills the read replica reliably with :
Error 'Access denied for user ''#'' (using password: NO)' on query. Default database: 'testdb'. Query: 'LOAD DATA INFILE '/rdsdbdata/tmp/SQL_LOAD-5ce65f0d-1a6a-11e3-af1b-12313c014074-352397698-1549.data' IGNORE INTO TABLE `test` FIELDS TERMINATED BY '\t' ENCLOSED BY '' ESCAPED BY '\\' LINES TERMINATED BY '\n' (`name`, `age`)'
To replicate the situation, I had a simple master and create a table called test:
CREATE TABLE `test` (
`name` varchar(25) NOT NULL,
`age` int(11) DEFAULT NULL,
PRIMARY KEY (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
It was replicated to the read replica successfully. Then i setup my input file :
# cat test.csv
steve,24
bob,34
courtney,12
ben,28
aidan,15
Then imported it with (Ignore the warnings, i didnt get my separator right but data went in) :
mysqlimport --local testdb test.csv
testdb.test: Records: 5 Deleted: 0 Skipped: 0 Warnings: 5
And that's all it takes to kill the read replica. I'm connecting to mysql as the user you create when you make the RDS instance, so it should have all permissions. But regardless, the read replica would have its own replication user. I've tried making the read-replicate NOT read-only, and this didn't seem to work.
mysql> status;
--------------
mysql Ver 14.14 Distrib 5.5.27, for FreeBSD9.0 (amd64) using 5.2
Connection id: 13481
Current database: testdb
Current user: testuser#ip-10-50-99-59.eu-west-1.compute.internal
SSL: Not in use
Current pager: more
Using outfile: ''
Using delimiter: ;
Server version: 5.6.13-log MySQL Community Server (GPL)
Protocol version: 10
Connection: saturn.xxxxxxxxxxx.eu-west-1.rds.amazonaws.com via TCP/IP
Server characterset: latin1
Db characterset: latin1
Client characterset: latin1
Conn. characterset: latin1
TCP port: 3306
Uptime: 8 hours 52 min 23 sec
Threads: 3 Questions: 775195 Slow queries: 0 Opens: 51017 Flush tables: 1 Open tables: 2000 Queries per second avg: 24.268
Would love if anyone could help
thanks
Steve
The reason this breaks is essentially because the read replica is replaying the binary logs and when it gets to your LOAD DATA LOCAL INFILE statement, it doesn't have that file.
RDS Creates a brand new read replica from an existing database by using a snapshot, not by replaying the bin logs.
So the solution is: after any LOAD DATA LOCAL INFILE is executed against the master you will have to delete your read replica and re-create it.
According to AWS technical support, this is a known issue when importing a CSV via LOAD DATA INFILE.
For me, issuing the following command caused the read replica to skip the error and sync successfully:
CALL mysql.rds_skip_repl_error;
There was no need to delete and re-create the read replica.
Update: This issue resolved itself when I upgraded the read replica to MySQL 5.6.
Is there a direct command line command that provides all mysql server information like below...This is provided using Mysql GUI administrator. Do we have some direct command to get this info ussing command line ?
Username:
Hostname:
Port:
Server Information
MySQL Version:
Network Name:
IP:
Client Information
Version:
Network name:
IP:
Operating System:
Hardware:
Look at following MySQL documentation:
SHOW VARIABLES
Following command will show you most of your desired information:
SHOW VARIABLES;
Only version:
select version();
EDIT:
What is the difference between show variables and show status?
SHOW STATUS provides server status information like Connections, Opened_tables, Bytes_received, Bytes_sent, etc.
More Info
SHOW VARIABLES shows the values of MySQL system variables like time_zone, version, max_connections, etc.
More Info
Try just status:
mysql> status
--------------
mysql Ver 14.14 Distrib 5.5.33, for osx10.7 (i386) using readline 5.1
Connection id: 3
Current database: somedb
Current user: someuser#localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.5.33 Source distribution
Protocol version: 10
Connection: 127.0.0.1 via TCP/IP
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
TCP port: 3306
Uptime: 38 min 53 sec
Threads: 2 Questions: 196 Slow queries: 0 Opens: 87 Flush tables: 1 Open tables: 80 Queries per second avg: 0.084
--------------