Ubutnu18.04の下にMySqlデータベースをインストールします

最近、Django関連の農業銀行プロジェクトに取り組んでおり、テスト環境をデプロイする必要があります。ここで、再度記録します。Ubuntu18で、各ソフトウェアとそのDjano関連のデプロイメントプロセスをインストールします。

MySqlのインストールについてお話しします。ここではUbuntu18を使用しています。インストール方法は次のとおりです。

apt install mysql-server

インストールが完了すると、システムはデフォルトでMysqlサービスを開始します

インストールが完了したら、次のコマンドを使用してログインします

mysql -u root -p

 -uはログインユーザーを選択することを意味し、-pはログインユーザーのパスワードを意味します。初期インストール用のパスワードはありません。Enterキーを押してデータベースに入るだけです。

 次に合格

show databases; 

現在のすべてのデータベースを表示できます。

 

 次に、データベースを初期化する必要があります。

Ubuntuコマンドラインで次のように入力します。

mysql_secure_installation
root@ip-172-31-23-232:/home/ubuntu# mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin? # 要安装验证密码插件吗?

Press y|Y for Yes, any other key for No: N
Please set the password for root here.

New password: # 输入要为root管理员设置的数据库密码

Re-enter new password:  # 再次输入密码
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y  # 删除匿名账户
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : N  # 禁止root管理员从远程登录,这里我没有禁止

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : U^HY   # 删除test数据库并取消对它的访问权限

 ... skipping.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y # 刷新授权表,让初始化后的设定立即生效
Success.

All done! 

mysqlコマンドラインをもう一度入力します。ここで、今すぐパスワードを使用してログインできます。

 その後、mysqlリモートログインアクセスを構成します。

構成ファイルの編集

vim /etc/mysql/mysql.conf.d/mysqld.cnf

下の図に示すように位置を見つけて変更します

コメントアウトします。保存して終了。

mysql -u root -p

mysqlコマンドラインを入力します

mysql> grant all on *.* to root@'%' identified by '你的密码' with grant option;

権限の更新

mysql> flush privileges;    # 刷新权限

脱落

mysql> exit

次のコマンドを実行してmysqlを再起動します

systemctl restart mysql

これで、myqlにリモートで直接アクセスできます。

それでもリモートアクセスができない場合は、サーバーのセキュリティグループの設定を確認して、対応するポートが開いているかどうかを確認してください。

この時点で、Ubuntu18へのmysqlサービスのインストールは完了しています。読んでくれてありがとう。賞賛とコミュニケーションをありがとう。ありがとうございました

 

 

おすすめ

転載: blog.csdn.net/u012798683/article/details/107312809