Linux centos は、初期パスワード設定のスーパーキャトルプロセスを無視して、エラーなしで mysql を迅速にインストールします

1 つ目は、インストールです

新しいバージョン (プロによるテストと何度も使用され、問題ありません)

mysqlのyumリポジトリファイルをダウンロードします。

[root@localhost /]#wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

mysqlソースをインストールする

[root@localhost /]yum -y install mysql mysql57-community-release-el7-11.noarch.rpm

MySQLをインストールする

yum -y install mysql-community-server

最後の行にエラーがあります。mysql-community-libs-compat-5.7.41-1.el7.x86_64.rpm の公開キーがインストールされていないため、
公開キーをインポートする必要があります (mysql の場合) -community-release-el7-5.noarch.rpm バージョン、この手順は必要ありません)

[root@localhost /]rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

再度インストールする

[root@localhost /]yum -y install mysql-community-server

2.mysqlサービスを開きます

mysqlを起動する

[root@localhost /]systemctl start mysqld.service

mysqlを自動的に起動するように設定する

[root@localhost /]systemctl enable mysqld.service
mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 四 2019-12-12 17:00:00 CST; 20s ago

MySQL の実行ステータスを表示します。

[root@localhost /]status mysqld.service 

active(running)と表示されている限り、実行中であることを意味します

あるいはこれも

[root@localhost /]ps aux|grep mysql

3. 構成

ホスト コンピューターの mysql サービスを開くことに注意してください。

ポート解放

外部ネットワークが mysql にアクセスし、navicat を使用してクラウド サーバーに接続できるようにするには、ファイアウォールを設定して、mysql のポート番号でファイアウォールを開くことができるようにする必要があります

[root@localhost /]systemctl start firewalld

ファイアウォール リリース ポート番号を追加: mysql ポート、デフォルトは 3306

[root@localhost /]firewall-cmd --zone=public --add-port=3306/tcp --permanent

ポートのオープンステータスを確認します。

[root@localhost /]firewall-cmd --list-ports 

Alibaba Cloud クラウド サーバーの場合は、コンソール セキュリティ グループにイングレスおよびエグレス リリース ルールを追加する必要もあります。

構成の表示と変更

mysql の場所を表示します。

[root@localhost /]which mysqld 

ここに画像の説明を挿入
上記のコマンドで見つかったディレクトリを使用して、mysql で使用される構成ファイルのデフォルトのパスを表示します。

[root@localhost /]/usr/sbin/mysqld --verbose --help |grep -A 1 'Default options' 

ここに画像の説明を挿入

いくつかの構成ファイル /etc/my.cnf を編集します

1. カスタム ポート: 追加します。port=端口号
2. データベースにリモート接続してエラーを報告します。
構成ファイルに「」を追加する必要があります。

sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'

3、character-set-server=utf8mb4
。。。

4. パスワードの設定

①以下のコマンドでログファイルにあるパスワードを確認します。

初期パスワードを見つける

[root@localhost /]# grep "password" /var/log/mysqld.log

ここに画像の説明を挿入

ここでのパスワードは 7IB<p#rpwC(u

ログイン

[root@localhost /]# mysql -uroot -p

上記のパスワードを入力し、Enter キーを押して確認します

mysql を入力し、パスワードの変更を開始します
** 各コマンドの後にセミコロンを追加する必要があることに注意してください**

mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY '1AB<p#rpwC(y'; 

また

set password for root@localhost = password('1AB<p#rpwC(y')

ここでは、root という名前のユーザーのパスワードを設定します。パスワードは 1AB<p#rpwC(y は
複雑なパスワードを設定する必要があります。複雑なパスワードを設定したくない場合は、セキュリティ レベルを変更できます)

構成を更新して即時効果を確認します

mysql>flush privileges;

②シークレットフリー設定パスワード(本バージョンでテスト予定):

1. my.cnf ファイルを編集します

[root@localhost ~]# vim /etc/my.cnf

[mysqld] 内


datadir=/var/lib/mysql
ソケット=/var/lib/mysql/mysql.sock

Skip-grant-table を以下に追加します

:wq 保存して終了

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
...

mysql サービスを再起動して設定を有効にします

[root@localhost ~]# systemctl restart mysqld

2. パスワードなしで mysql にログインします (ユーザー名を入力して Enter キーを押します)。

[root@localhost ~]# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.46 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

3. パスワードを変更してパスワードを設定します。
mysql> update mysql.user set password=password('設定したいパスワード') where user='ユーザー名';

mysql> update mysql.user set password=password('rootp') where user='root';
Query OK, 4 rows affected (0.01 sec)
Rows matched: 4  Changed: 4  Warnings: 0

これは、MySQL サービスを再起動せずに直接有効になり、
現在のユーザーおよび特権テーブルのユーザー情報と権限設定は、MySQL データベースの組み込みライブラリからメモリに抽出されます。

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

やめる

mysql> quit;
Bye

4. my.cnf を変更し、設定を復元します。

[root@localhost ~]# vim /etc/my.cnf

[mysqld] に以前に挿入した Skip-grant-tables を削除します。

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
...

mysql サービスを再起動すると、設定が有効になります。

[root@localhost /]# systemctl restart mysqld

5. ログイン検証
[root@localhost ~]# mysql -u root -p
Enter キーを押した後、設定したばかりのパスワード rootp を入力します。

おすすめ

転載: blog.csdn.net/weixin_45752941/article/details/103730917
おすすめ