Help us understand the problem. What is going on with this article?

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

More than 1 year has passed since last update.

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.

hit
なんとなくデータベースエンジニア。なんとなくメモしてます
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした