Ubuntu 安装MySQL 配置

8 篇文章 0 订阅
5 篇文章 0 订阅

准备

安装

  1. 下面命令依次执行,遇到 Y/n 输入Y 回车。
sudo apt-get install mysql-server
sudo apt-get install mysql-client
sudo apt-get install libmysqlclient-dev
  1. 检查是否安装成功sudo systemctl -l | grep mysql
    在这里插入图片描述

配置

  • 直接从第 1. 步骤 看
  • 使用root链接MySQL不需要密码,或者执行sudo cat /etc/mysql/debian.cnf获取MySQL另一个默认用户密码
sudo cat /etc/mysql/debian.cnf
# 下面是返回结果
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host     = localhost
user     = debian-sys-maint
password = I7VJso2cQyIOJmq9
socket   = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host     = localhost
user     = debian-sys-maint
password = I7VJso2cQyIOJmq9
socket   = /var/run/mysqld/mysqld.sock
  • 修改密码:进入MySQLmysql -uroot -p 回车,并且执行
use mysql;
# 更新 plugin 字段为 mysql 默认值:
update user set plugin='mysql_native_password';
# 修改密码
alter user 'root'@'localhost' identified by 'root';
# 刷新权限
flush privileges;
  1. 初始化配置
sudo mysql_secure_installation
Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT 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 component?

Press y|Y for Yes, any other key for No: 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) : N(是否删除匿名用户,我选择否)

 ... skipping.


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(不允许用户远程登录? 我选择否)
Success.

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) : N(删除测试数据库并访问它?我选择否)

 ... 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!

设置远程登录

use mysql;
update user set host='%' where user='root' and host='localhost';
GRANT ALL PRIVILEGES ON root TO 'root'@'%';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root_passwd';

安装位置及命令

  • 安装位置/etc/mysql
  • 命令
  1. 查看状态,默认启动,默认开机启动 systemctl status mysql
  2. 关闭开机启动 sudo systemctl disable mysql
  3. 设置开机启动 sudo systemctl disable mysql
  4. 启动 sudo systemctl start mysql
  5. 关闭 sudo systemctl stop mysql
  6. 重启 sudo systemctl restart mysql.service
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值