MySQL Note1:Ubuntu安装MySQL

MySQL Note1:Ubuntu安装MySQL

Ubuntu安装MySQL

 
# 1. 更新包 sudo apt update # 2. 安装Mysql sudo apt install mysql-server # 3. 查看MySQL mysql -V

MySQL初始化配置

sudo mysql_secure_installation
配置项较多,如下所示:
  • 我这里设置简单的密码:henggao
#1 VALIDATE PASSWORD PLUGIN can be used to test passwords... Press y|Y for Yes, any other key for No: N (选择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 (选择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 (选择N,允许root远程连接) #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 (选择N,不删除test数据库) #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 (选择Y,修改权限立即生效)

检查MySQL服务状态

systemctl status mysql.service
notion image
 
 

访问数据库

  • 以root进入,密码:henggao
sudo mysql -uroot -p #切换数据库 mysql>use mysql; #查询用户表命令: mysql>select User,authentication_string,Host from user; #查看状态 select host,user,plugin from user;
notion image
 
 
 
 
参考:
Ubuntu20.04安装Mysql_風の住む街~的博客-CSDN博客_ubuntu20.04安装mysql
在Ubuntu中,默认情况下,只有最新版本的MySQL包含在APT软件包存储库中,要安装它,只需更新服务器上的包索引并安装默认包apt-get。 如果因为程序兼容性问题,要安装5.7版本,则可以同过下载安装。 https://downloads.mysql.com/archives/community/ 进入你的下载文件夹下面 tar -xvf mysql-server_5.7.13-1ubuntu16.04_i386.deb-bundle.tar 解压了这个包之后会在文件夹看到多个deb文件 安装顺序(很重要的,因为存在依赖关系) : libmysqlclient20_5.7.13-1ubuntu16.04_i386.deb libmysqlclient-dev_5.7.13-1ubuntu16.04_i386.deb libmysqld-dev_5.7.13-1ubuntu16.04_i386.deb mysql-common_5.7.13-1ubuntu16.04_i386.deb mysql-community-source_5.7.13-1ubuntu16.04_i386.deb mysql-community-client_5.7.13-1ubuntu16.04_i386.deb mysql-community-server_5.7.13-1ubuntu16.04_i386.deb mysql-server_5.7.13-1ubuntu16.04_i386.deb 可以一次性按顺序输入安装包名字: sudo dpkg -i libmysqlclient20_5.7.13-1ubuntu16.04_i386.deb libmysqlclient-dev_5.7.13-1ubuntu16.04_i386.deb libmysqld-dev_5.7.13-1ubuntu16.04_i386.deb mysql-common_5.7.13-1ubuntu16.04_i386.deb mysql-community-source_5.7.13-1ubuntu16.04_i386.deb mysql-community-client_5.7.13-1ubuntu16.04_i386.deb mysql-community-server_5.7.13-1ubuntu16.04_i386.deb mysql-server_5.7.13-1ubuntu16.04_i386.deb 也可以一个一个来安装(这样子能够搞懂依赖的关系) 安装过程中可能缺少依赖,所以可以用: sudo apt-get install [文件名] eg:这里面的问题是缺少libaio1和libmecab2,所以可以用: sudo apt-get install libaio1 libmecab2 如果还是不能安装使用: sudo apt-get -f install 安装完成之后: 查看mysql服务状态: service mysql start 进入MySQL mysql -u root -p #命令1 更新源 sudo apt-get update #命令2 安装mysql服务 sudo apt-get install mysql-server sudo mysql_secure_installation 配置项较多,如下所示: #1 VALIDATE PASSWORD PLUGIN can be used to test passwords...
Ubuntu20.04安装Mysql_風の住む街~的博客-CSDN博客_ubuntu20.04安装mysql