0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

私的MySQLチートシート

Last updated at Posted at 2025-04-28

MySQLチートシート

インストール

sudo pacman -Syu
sudo pacman -S mysql mysql-workbench
sudo mkdir -p /var/lib/mysql/
sudo chown -R mysql:mysql /var/lib/mysql
sudo chmod -R 750 /var/lib/mysql
sudo mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
sudo systemctl enable --now mysqld

もし、dbeaverなどでrootにログインできなかったら、

UPDATE mysql.user SET authentication_string=PASSWORD('新しいパスワード'), plugin='mysql_native_password' WHERE User='root';
FLUSH PRIVILEGES;
EXIT;

データインポートするのが遅かったら

一番早いのは、ログインしてから

use [database];
source ~/file.sql

mysql import, export中の進捗をログで表示

インストール

sudo pacman -S pv

実際に使ってみる

# import
pv ~/downloads/forum.sql | sudo mariadb --max_allowed_packet=64M web

# export
mysqldump --max_allowed_packet=64M -u root -p web | pv > ~/downloads/forum.sql

exportで失敗しないために

mysqldumpコマンドの引数で、max_allowed_packetを指定する

mysqldump --max_allowed_packet=64M -u root -p web > ~/path/to/sample.sql

auth_socketプラグインを使っているかどうか検証

SELECT user, host, plugin FROM mysql.user WHERE user='mc';

INSERTでSELECT参照

例として、membersテーブルのものをusersテーブルに移植する。

INSERT INTO users (name, password, email)
SELECT name, password, email
FROM members;
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?