Linux 安装mysql

Ubuntu 安装mysql8

  1. sudo apt-get update #更新源

  2. sudo apt-get install mysql-server #安装mysql服务

  3. 安装过程中 继续执行选 y

  4. sudo mysql_secure_installation #初始化配置

  5. 接下来会逐步选择设置

    #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`,修改权限立即生效)
    
  6. systemctl status mysql.service #检查mysql服务状态

    https://img-blog.csdnimg.cn/20200521170311694.png

  7. 设置远程访问

    1. sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf #找到 bind-address 修改值为 0.0.0.0(如果需要远程访问)

    2. sudo /etc/init.d/mysql restart #重启mysql

    3. sudo mysql -uroot -p #输入密码进入mysql

    4. mysql>use mysql; #切换数据库

    5. select host,user,plugin from user; #查看状态

    6. 如user为root的host为localhost时,则修改为%即可远程连接,%是允许所有ip访问

    #设置权限与密码
    mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '密码'; #使用mysql_native_password修改加密规则
    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '密码' PASSWORD EXPIRE NEVER; #更新一下用户的密码
    mysql> UPDATE user SET host = '%' WHERE user = 'root'; #允许远程访问
    
    #刷新cache中配置 刷新权限
    mysql>flush privileges; 
    mysql>quit;
    
    1. systemctl restart mysql.service #重启mysql 服务

    2. 此时,即可使用navicat本地连接服务器中的mysql了

ubuntu离线安装mysql5.7

mysql官网下载mysql5.7离线包

  1. 在服务器里直接获取(服务器需要联网)
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-server_5.7.31-1ubuntu18.04_amd64.deb-bundle.tar
  1. 也可以直接将网址粘贴到浏览器下载安装压缩包
https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-server_5.7.31-1ubuntu18.04_amd64.deb-bundle.tar
  1. 百度网盘下载
https://pan.baidu.com/s/15kjX-ybetkUJD7TZPz0uLQ
提取码: qozu

将下载好的mysql-server_5.7.31-1ubuntu18.04_amd64.deb-bundle.tar压缩包导入linux服务器,然后进行下面的操作。

# 新建目录
mkdir mysql
mv mysql-server_5.7.31-1ubuntu18.04_amd64.deb-bundle.tar ./mysq

# 解压
cd mysql
sudo tar -vxf mysql-server_5.7.31-1ubuntu18.04_amd64.deb-bundle.tar

# 解压出来的deb安装包如下:
libmysqlclient20_5.7.31-1ubuntu18.04_amd64.deb
mysql-client_5.7.31-1ubuntu18.04_amd64.deb
mysql-community-source_5.7.31-1ubuntu18.04_amd64.deb
mysql-server_5.7.31-1ubuntu18.04_amd64.deb
mysql-common_5.7.31-1ubuntu18.04_amd64.deb
mysql-testsuite_5.7.31-1ubuntu18.04_amd64.deb
libmysqlclient-dev_5.7.31-1ubuntu18.04_amd64.deb
mysql-community-client_5.7.31-1ubuntu18.04_amd64.deb
mysql-community-server_5.7.31-1ubuntu18.04_amd64.deb
libmysqld-dev_5.7.31-1ubuntu18.04_amd64.deb
mysql-community-test_5.7.31-1ubuntu18.04_amd64.deb

# 删除2个测试相关的包
sudo rm -f mysql-testsuite_5.7.31-1ubuntu18.04_amd64.deb
sudo rm -f mysql-community-test_5.7.31-1ubuntu18.04_amd64.deb

利用dpkg进行安装deb包

  1. 用dpkg进行安装
sudo dpkg -i mysql-*.deb

1.jpg
2. 若报以下错误
2.jpg
3. 执行apt --fix-broken install
4. 提示输入2次root密码,然后安装成功
6.jpg

安装完成后查看mysql版本和服务

mysql -V  # 查看mysql版本
netstat -tap | grep mysql  # 查看mysql服务

7.jpg

  • 如上图所示说明安装成功。
posted @ 2022-03-09 11:18  小小爬虫  阅读(63)  评论(0编辑  收藏  举报