Linux MySQLのソフトリンクの作成について

3781 ワード

**
一、準備
**チェック:
rpm -qa | grep mysql

ユーザーグループを追加し、mysqlを専門に管理し、セキュリティを向上
$> groupadd mysql

$> useradd -r -g mysql -s /bin/false mysql

二、取り付け
1、mysql-5.7.23-linux-glibc 2を解凍する.12-x86_64.tar.gzを/usr/local/mysqlフォルダに移動
$> tar -xvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz -C /usr/local
$> mv mysql-5.7.23-linux-glibc2.12-x86_64 /usr/local/mysql
$> chown -R mysql:mysql mysql

2、mysqlのサービスを配置し、support-filesの下のmysqlを配置する.サーバを/etc/initにコピーします.d/下にmysqlと名付けます
$> cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

3、修正/etc/init.d/mysqlのパラメータ
$> vi /etc/init.d/mysql
#      
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data

4、mysqlを構成するプロファイル、その他のバージョンmysqlのsupport-filesディレクトリの下にデフォルトのプロファイルがありますが、5.7.23このバージョンはありません.自分で準備する必要があります.以下は簡単な基本構成を提供して、/etc/の下でmyを新規します.cnf、デフォルトのデータベースプロファイルもあるので、直接上書きすればいいというプロンプトが表示される場合があります.
$> touch /etc/my.cnf
#my.cnf    
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[client]
port = 3306
default-character-set=utf8
[mysqld]
#       
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character-set-server=utf8
default_storage_engine = InnoDB
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/var/log/mysql/mariadb/mariadb.log
pid-file=/var/run/mysql/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

5、関連ディレクトリファイルの作成
$> mkdir -p /var/log/mysql/mariadb
$> touch /var/log/mysql/mariadb/mariadb.log
$> chown -R mysql:mysql /var/log/mysql
$> mkdir /var/run/mysql
$> chown -R mysql:mysql /var/run/mysql
$> mkdir /var/lib/mysql
$> chown -R mysql:mysql /var/lib/mysql
$> ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

6、mysqlのbinディレクトリに切り替える次のコマンドを実行してデータベースを初期化する
$> rm -rf /usr/local/mysql/data/* (  /usr/local/mysql/data       )
$> ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

7、実行が完了すると自動的にデフォルトの初期パスワードが生成されます実行記録では、コピーに注意してください
8、mysqlサービスを起動し、以下に起動成功の文字を提示する
$> service mysql start
    :Starting MySQL. SUCCESS! 

9、mysqlの環境変数を設定する
$> cd /etc/profile.d
$> touch mysql.sh
#mysql.sh      
MYSQL_HOME=/usr/local/mysql
PATH=$PATH:$MYSQL_HOME/bin
export MYSQL_HOME PATH
 
$> source /etc/profile

三、ログイン1、ログイン
$> mysql -uroot -p
#         

2、パスワードの変更
mysql> set password=password('   ');

3、リモートログインを開く
# grant all privileges on  .  to   @'%' identified by '    ';
 
mysql> grant all privileges on *.* to root@'%' identified by 'root  ';
 
mysql> flush privileges;

4、電源オンの設定(必要でない、使用に影響しない)
$> chkconfig --list
$> chkconfig --add mysql
$> chkconfig mysql on
#     chkconfig --list            ,
#   mysql 2-5    (       on)   ,
#  mysql