Mysql command line

# connecting to exifweb database:
mysql -u exifweb -p
use exifweb
insert into AppConfig values (null, 'false', 'cpu summary: use sum on ps aux command', now());
exit or CTRL+D

# https://dev.mysql.com/doc/mysql-utilities/1.6/en/mysql-utils-intro-connspec-mylogin.cnf.html
# avoid warning for commands like:
mysql -u root -pmysqlpassword -e 'FLUSH QUERY CACHE'

# see /etc/mysql/mysql.conf.d/mysqld.cnf for --socket
# see $HOME/.mylogin.cnf
mysql_config_editor set --login-path=local --host=127.0.0.1 --user=root --socket=/var/run/mysqld/mysqld.sock --password
# or using the --port option:
mysql_config_editor set --login-path=local --host=127.0.0.1 --user=root --port=3306 --password
mysql_config_editor print --login-path=local

# The result of the command below:
mysqlserverinfo --server=local --format=vertical
# is strange: 
# ERROR: Access denied for user 'root'@'127.0.0.1' using password: YES

# the below command works fine so I guess mysqlserverinfo don't work well with mysql_config_editor
mysqlserverinfo --server=root:xxx@127.0.0.1 --format=vertical

# remove with:
mysql_config_editor remove --login-path=local

# now you have no warnings:
mysql --login-path=local -e 'FLUSH QUERY CACHE'

# other example, e.g. connect to db1 then show tables:
mysql --login-path=local db1
show tables;

One thought on “Mysql command line”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.