1、->sudo apt-get install mysql-server #安装MySQL 服务2、->sudo apt-get install mysql-client #3、->sudo mysql_secure_installation #配置MYSQL#以下是具体内容Securing the MySQL server deployment. #保护MySQL服务器部署。Connecting to MySQL using a blank password. #使用空密码连接到MySQL。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 #密码插件是检测密码强度,如果个人测试安装MYSQL建议不要加载,不然会要求创建比较复杂的密码(同时包含大小写字母,特殊字符,数字等) Please set the password for root here.New password: #输入密码Re-enter new password: #再次输入密码, 如果刚启用了密码插件,可能会提示密码强度低,重新设置 By default, a MySQL installation has an anonymous user, #默认情况下,MySQL安装有一个匿名用户,allowing anyone to log into MySQL without having to have #允许任何人登录MySQL而不必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) : y #不允许远程根登录? Success. By default, MySQL comes with a database named \’test\’ that #默认情况下,MySQL附带一个名为“test”的数据库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 #删除测试数据库并访问它? – 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、—>sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf 或者—>sudo vim /etc/mysql/my.cnf #mysql.conf.d/mysqld.cnf 这个文件在有些版本 里可能没有#注释掉 bind-address = 127.0.0.1 5、->sudo mysql -u root -p #root账号登录MYSQL->输入MYSQL root 的密码mysql->grant all on *.* to root@\’%\’ identified by \’MYSQL密码\’ with grant option;mysql->flush privileges; #刷新权限mysql->exit #退出MYSQL—>systemctl restart mysql #重启MYSQL服务—>systemctl status mysql.servise #查询MYSQL服务状态 #可能出现systemctl:未找到命令或者—>sudo service mysql start # start 可以替换为:[ stop(停止服务) / restart(重启服务) / status(查询服务状态) ] ——————————MySQL安装完成——————————备注:1、安装第4、5两步是为了能够远程访问登录该服务器的MySQL服务. 具体讲解:第4步,是配置mysql允许远程访问. 配置文件中 bind-address=127.0.0.1 是Mysql 绑定了本地地址. 也可以改为bind-address=0.0.0.0,效果一致 第5步,是将权限赋给root用户,所有ip都能连接, “%”指任何IP地址的连接 grant:赋权命令 all:当前用户的所有权限 on:介词 *.*:当前用户对所有数据库和表的相应操作权限 to:介词 ‘root’@’%’:权限赋给root用户,所有ip都能连接 identified by‘MYSQL密码’:MySQL 连接时输入密码 with grant option:允许级联赋权.2、MySQL 默认使用的是 3306 端口,如果使用云服务器,需要在安全组中 将云服务器的 3306 端口开放3、服务器本机执行—>netstat -an|grep 3306 # 为查询3306端口命令显示:tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 为成功开放3306端口.显示:tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 为没有开放3306端口.
Ubuntu 18 服务器操作笔记 之 安装MYSQL
未经允许不得转载:爱站程序员基地 » Ubuntu 18 服务器操作笔记 之 安装MYSQL