ホームページ  >  記事  >  データベース  >  centos7 に mysql と mysqlclient をインストールするときに遭遇する落とし穴を解決する方法

centos7 に mysql と mysqlclient をインストールするときに遭遇する落とし穴を解決する方法

PHPz
PHPz転載
2023-05-28 11:10:061518ブラウズ

1. mysql yum ソースを追加します

mysql 公式ウェブサイト>ダウンロード>mysql yum リポジトリを追加して、適切なバージョンの yum ソースを見つけます

$wget https://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm
$sudo rpm -uvh mysql80-community-release-el7-2.noarch.rpm
 
#查看mysql数据库各个版本信息
$yum repolist all | grep mysql

2 . インストールのバージョンを選択します

/etc/yum.repos.d/mysql-community.repo ファイルを変更し、mysql5.7 バージョンを選択します

# enable to use mysql 5.6
[mysql56-community]
name=mysql 5.6 community server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
enabled=0 # 禁止
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/rpm-gpg-key-mysql
 
# enable to use mysql 5.7
[mysql57-community]
name=mysql 5.7 community server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1 # 安装
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/rpm-gpg-key-mysql
 
[mysql80-community]
name=mysql 8.0 community server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=0 # 禁止
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/rpm-gpg-key-mysql

3. インストール#

#执行以下命令安装mysql
yum install mysql-community-server
#启动mysql(centos7中)
systemctl start mysqld.service
#低版本的操作系统可用以下指令
service mysqld start
#查看mysql状态
systemctl status mysqld.service
#低版本操作系统可用以下指令
service mysqld status

4. パスワードの表示と変更#

$grep "password" /var/log/mysqld.log
2019-04-11t08:17:16.706096z 1 [note] a temporary password is generated for root@localhost: ux#bkam(k1q-
$mysql -u root -p
>ux#bkam(k1q-
 
# 修改密码
mysql>alter user 'root'@'localhost' identified by 'complex password';
mysql>set global validate_password_policy=0;
mysql>set global validate_password_length=1;
mysql>alter user 'root'@'localhost' identified by 'simple password';
#5. オープン 3306 ポートの設定

認可方法により、任意のホストが mysql サーバーにアクセスできるようになります: [通常はこれを使用し、ポート アクセスを制限し、firewalld に任せます]

mysql>grant all privileges on *.* to 'root'@'%' identified by 'password' with grant option;

IP アクセスを制限する:

mysql>grant all privileges on *.* to 'jack'@'10.10.50.127' identified by 'password' with grant option;

以上がcentos7 に mysql と mysqlclient をインストールするときに遭遇する落とし穴を解決する方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事はyisu.comで複製されています。侵害がある場合は、admin@php.cn までご連絡ください。