首页 > 数据库 >Ubuntu 安装 MySQL 5.7

Ubuntu 安装 MySQL 5.7

时间:2022-08-25 13:35:16浏览次数:59  
标签:sudo 5.7 Ubuntu user mysql MySQL password root

一、安装MySQL

1. 删除Mysql 数据库

sudo apt autoremove --purge mysql-server-*
sudo apt remove mysql-server
sudo apt autoremove mysql-server
sudo apt remove mysql-common

2. 安装Mysql 

sudo apt-get update #更新包
sudo apt install mysql-server-5.7

  查看 MySQL 版本

sudo mysql -V

查看MySQL默认账号和密码

sudo cat /etc/mysql/debian.cnf

二、配置MySQL

sudo mysql_secure_installation
#1
VALIDATE PASSWORD PLUGIN can be used to test passwords...
Press y|Y for Yes, any other key for No: N 
 
#2
 Please set the password for root here...
 New password: (输入密码)
Re-enter new password: (重复输入)
 
#3
 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...
 Remove anonymous users? (Press y|Y for Yes, any other key for No) : N 
 
#4
 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 
 
#5
 By default, MySQL comes with a database named 'test' that
 anyone can access...
 Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N 
 
#6
 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 

三、查看mysql服务状态

systemctl status mysql.service

四、修改root账户秘密认证方式

sudo cat /etc/mysql/debian.cnf  # 查看 Password 后面的密码
mysql -u debian-sys-maint -p    #进入 mysql 命令模式


mysql> use mysql;
mysql> select user,host,authentication_string from user; mysql> update mysql.user set authentication_string=password('密码') where user='root' and Host ='localhost'; mysql> update user set plugin='mysql_native_password'; mysql> select Host, User, plugin from user; mysql> flush privileges; mysql> quit; 

五、配置远程访问mysql

修改配置文件,注释掉bind-address = 127.0.0.1

sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
:wq

mysql -uroot -p

mysql> use mysql;
mysql> update user set host='%' where user = 'root';
mysql> flush privileges;

 

#重启
sudo service mysql restart  
#查看状态
systemctl status mysql.service

 

标签:sudo,5.7,Ubuntu,user,mysql,MySQL,password,root
From: https://www.cnblogs.com/vipsoft/p/16623918.html

相关文章

  • 【MySQL】mysqldump从所有数据库备份中还原某个指定的库
    有时候,需要还原某个特定的数据库,但是在备份的时候却又备份了所有的数据库。这时,就可以通过参数--one-database选项来还原指定的数据库。mysql-uroot-p[pwd]--one-data......
  • MySQL查询性能优化七种武器之索引下推
    前面已经讲了MySQL的其他查询性能优化方式,没看过可以去了解一下:MySQL查询性能优化七种武器之索引潜水MySQL查询性能优化七种武器之链路追踪今天要讲的是MySQL的另一种查......
  • ubuntu18 : QEMU中新建S3C2440模拟器
    1.下载wgethttp://repo.or.cz/w/qemu/mini2440.git/snapshot/HEAD.tar.gz2.解压tar-zxvfHEAD.tar.gz cdmini2440-HEAD-18b91f23.安装依赖包sudoapt-getinstal......
  • 详解MySQL隔离级别
    一个事务具有ACID特性,也就是(Atomicity、Consistency、Isolation、Durability,即原子性、一致性、隔离性、持久性),本文主要讲解一下其中的Isolation,也就是事务的隔离性。概......
  • 【mysql_8】
    网址:https://dev.mysql.com/downloads/MySQLCommunityServerLinux-Generic根据自己的系统选择安装包,我这里选择的是X8664位 第一步:1)切换到/usr/local下2......
  • 【索引】Mysql索引常见问题
    1、什么是索引:索引是一种数据结构,用来提高在数据表中的数据查询效率,同时也是随机读和有效排序的基础。2、为什么使用索引:根本原因在于磁盘速度与内存速度差距甚大,所......
  • MySQL-索引
    为什么需要索引?定义:索引是一个列或多个列进行排序的数据结构作用:索引能大幅提高查找效率缺点:创建和更新索引会耗费空间和时间查找结构进化一个个找:实现简单:太慢二分......
  • 统信 UOS Server 20 修改 MySQL 数据目录(datadir)
    一、环境说明操作系统:UnionTechOSServer20Enterprise数据库:MySQL5.7注1:统信UOS查看系统版本方式#方式一,查看发行版信息cat/etc/os-release#方式二,查看......
  • MySQL分区介绍与使用
    一、MySQL分区创建 MySQL创建方式一共有四种:range、list、hash和key。1.range(官方文档)1.1intcreatetablestaff(idint(32)notnull,code_varchar(30),......
  • 学习:python操作mysql(一)
    1、安装mysql,这里我大哥提供给我的是解压版的安装包为了防止自己以后忘了记录一下安装方式第一步将安装包解压到提前准备好的文件夹内  第二步配置环境变量path......