Skip to content

Instantly share code, notes, and snippets.

@t-ubukata
Last active July 1, 2025 05:11
Show Gist options
  • Select an option

  • Save t-ubukata/5594336ac2b030977c97475d2852b174 to your computer and use it in GitHub Desktop.

Select an option

Save t-ubukata/5594336ac2b030977c97475d2852b174 to your computer and use it in GitHub Desktop.
# Status
systemctl status mysqld
# Start
systemctl start mysqld
# Stop
systemctl stop mysqld
# Restart
systemctl restart mysqld
# Connect
mysql -u user -p -h hostname -p port -D db
# Runs a query.
mysql -u user -p -h hostname -p port -D db -e "select * from foo;"
# Runs a file.
mysql -u user -p -h hostname -p port -D db < foo.sql
# MySQL commands
## Help.
\h
## Quits.
\q
## Lists databases.
show databases;
## Lists tables.
show tables;
## Shows table definition.
desc foo;
## Shows data directory.
select @@datadir;
# Config file
/etc/my.cnf
/etc/mysql/my.cnf
SYSCONFDIR/my.cnf
$MYSQL_HOME/my.cnf
defaults-extra-file
~/.my.cnf
~/.mylogin.cnf
DATADIR/mysqld-auto.cnf
## Data directory setting
datatdir
## Log setting
log-error
general_log_file
log-bin
slow_query_log_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment