Difference between revisions of "MySQL"

From Vrieze Wiki
Jump to navigation Jump to search
m
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
== MySQL ==
 
== MySQL ==
Connecting to MySQL server in bash
+
Connecting to MySQL server in bash.
 
  <syntaxhighlight lang="bash">
 
  <syntaxhighlight lang="bash">
 
  # Connect to mysql server
 
  # Connect to mysql server
  mysql --host=<ip.address> --user=<username> --password=<password>
+
  mysql -u<username> -p -h <ip> --ssl-ca=server-ca.pem --ssl-cert=client-cert.pem --ssl-key=client-key.pem
 
  </syntaxhighlight>
 
  </syntaxhighlight>
  
MySQL commands
+
Once connected, some simple MySQL commands to browse and query.
 
  <syntaxhighlight lang="mysql">
 
  <syntaxhighlight lang="mysql">
 
  show databases;      # show the databases
 
  show databases;      # show the databases
Line 13: Line 13:
 
  select * from table_name limit 10; # to see what's in a table (first ten entries)
 
  select * from table_name limit 10; # to see what's in a table (first ten entries)
 
  select * from user_location where user_id='6346669087044735461' order by sample_time desc limit 10;
 
  select * from user_location where user_id='6346669087044735461' order by sample_time desc limit 10;
 +
</syntaxhighlight>
 +
 +
Copy remote table to local file.
 +
<syntaxhighlight lang="bash">
 +
mysql -u<username> -p -h <ip> --ssl-ca=server-ca.pem \
 +
                              --ssl-cert=client-cert.pem \
 +
                              --ssl-key=client-key.pem \
 +
                              userdata_schema \
 +
                              -e "select * from user_location" > <export-file>.csv
 
  </syntaxhighlight>
 
  </syntaxhighlight>

Latest revision as of 12:43, 17 April 2020

MySQL

Connecting to MySQL server in bash.

 # Connect to mysql server
 mysql -u<username> -p -h <ip> --ssl-ca=server-ca.pem --ssl-cert=client-cert.pem --ssl-key=client-key.pem

Once connected, some simple MySQL commands to browse and query.

 show databases;      # show the databases
 use userdata_schema; # connect to a particular database
 show tables;         # list the tables within the database
 select * from table_name limit 10; # to see what's in a table (first ten entries)
 select * from user_location where user_id='6346669087044735461' order by sample_time desc limit 10;

Copy remote table to local file.

 mysql -u<username> -p -h <ip> --ssl-ca=server-ca.pem \
                               --ssl-cert=client-cert.pem \
                               --ssl-key=client-key.pem \
                               userdata_schema \
                               -e "select * from user_location" > <export-file>.csv