数据库—2(ubuntu 18.04 安装 mysql)

tech2023-02-27  99

1. 检查有没有安装mysql 数据库

#dpkg -l | grep mysql #apt install mysql-server #如果安装 先根据版本进行卸载 我的就版本是5.7 apt-get autoremove --purge mysql-server-5.7

2. 检查mysql是否安装成功,安装成功后处于监听状态

  #netstat -tap | grep mysql

3. 对数据库进行初始化操作,便于数据库能正常安全运行

# 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 # 我选择N Please set the password for root here. New password:  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) : y # 删除test数据库并取消对它的访问权限  - Dropping test database... Success.  - Removing privileges on test database... Success. 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! 

4. 配置mysql允许远程访问, /etc/mysql/mysql.conf.d/mysqld.cnf 配置文件:

   注释掉bind-address          = 127.0.0.1

5. 进入mysql数据库,执行授权命令:

#mysql -u root -p #root用户能任意主机访问所有的数据库, '你的密码‘为# mysql_secure_installation 配置的root密码 mysql> grant all on *.* to root@'%' identified by '你的密码' with grant option;        #只允许root用户本地访问所有的数据库 mysql> grant all on *.* to root@localhost identified by '你的密码' with grant option;  mysql>CREATE DATABASE kaitest; #kaikai用户可以从任意机器上登入mysql的kaitest数据库 ,以密码654321 mysql> GRANT ALL PRIVILEGES ON kaitest.* TO kaikai@"%" IDENTIFIED BY "654321" WITH GRANT OPTION; #允许myuser 用户在192.168.1.76 主机上 以 mypassword 访问任意数据库 mysql>GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.76' IDENTIFIED BY 'mypassword' WITH GRANT OPTION; mysql> flush privileges;    # 刷新权限 mysql> exit

 

6.重启数据库

#systemctl restart mysql     #重启数据库

 

远程查看数据库

下载nvicat For MySQL 数据库查看工具

 

可以看到root用户能够访问到的数据库

 

 

 

最新回复(0)