49
54

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MySQLのデータベースを初期化する

Last updated at Posted at 2014-10-07

MySQL を初期化する方法

MySQLが起動しなくて、にっちもさっちにいかなかった場合の初期化方法をメモします
ちなみに、これやるとデータベースからデータから、アカウントからすべて消えてしまいますので注意!!!

操作手順

プロセスが起動しているか確認


# ps -efw | grep -i mysql
root     12787     1  0 06:20 pts/0    00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/server01.s-quad.com.pid
mysql    13041 12787  0 06:20 pts/0    00:00:14 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/server01.s-quad.com.err --pid-file=/var/lib/mysql/gate02.s-quad.com.pid --socket=/var/lib/mysql/mysql.sock --port=3306
root     13203  8766  0 07:53 pts/0    00:00:00 grep -i mysql

サービスの停止

通常のサービス停止手順


# /etc/init.d/mysql stop
Shutting down MySQL... SUCCESS! 

サービスの停止ができなかったら、全部KILL!!

# killall mysqld

既存のデータフォルダを気休めバックアップ(気休め)

# cd /var/lib
# cp -arf mysql/ mysql_backup/

mysql/ の中身を全部消す!!


# cd /var/lib/mysql; 
# rm -rf *

MySQLの初期化を行う

めらめらとコンソールからなにやらメッセージが出てきます

# su - mysql 
$ mysql_install_db --datadir=/var/lib/mysql

MySQLの起動

初期化が終わりましたらMySQLを起動します


$ exit
# /etc/init.d/mysql start
Starting MySQL. SUCCESS!
# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.0.12-MariaDB-log MariaDB Server

Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

49
54
2

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
49
54

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?