Ubuntu Mysql安装教程

本文详细介绍了如何在Linux系统中安装MySQL服务器,包括验证安装状态、设置安全配置、创建用户、登录数据库以及处理编译错误。此外,还涉及到了卸载MySQL的步骤以及创建数据库、表和插入数据的操作。在配置过程中,强调了限制root用户远程登录和移除匿名用户的重要性。
摘要由CSDN通过智能技术生成
  • 1、安装

    sudo apt install mysql-server
    
  • 2、验证MySQL服务器状态

    sudo systemctl status mysql
    
  • 3、密码和配置设置

    root@wy:/home/wy/TinyWebServer-master# 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: y
    
    There are three levels of password validation policy:
    
    LOW    Length >= 8
    MEDIUM Length >= 8, numeric, mixed case, and special characters
    STRONG Length >= 8, numeric, mixed case, special characters and dictionary                                                                                                                                                                                                                                 file
    
    Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 12345678
    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    
    Estimated strength of the password: 50
    Do you wish to continue with the password provided?(Press y|Y for Yes, any othe                                                                                                                                                                                                               r key for No) : y
    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) : 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) : n
    
     ... skipping.
    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                                                                                                                                                                                                               ) : 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、登陆

    mysql -u root -p
    
  • 5、卸载

    删除mysql的数据文件
    sudo rm /var/lib/mysql/ -R
    
    删除mysql的配置文件
    sudo rm /etc/mysql/ -R
    
    自动卸载mysql(包括server和client)
    sudo apt-get autoremove mysql* --purge
    sudo apt-get remove apparmor
    
    然后在终端中查看MySQL的依赖项:dpkg --list|grep mysql
    
  • 6、创建用户

    命令:
    CREATE USER ‘username’@’host’ IDENTIFIED BY ‘password’;
    说明:
    username:你将创建的用户名
    host:指定该用户在哪个主机上可以登陆,如果是本地用户可用localhost,如果想让该用户可以从任意远程主机登陆,可以使用通配符%
    password:该用户的登陆密码,密码可以为空,如果为空则该用户可以不需要密码登陆服务器
    例子:
    CREATE USER ‘hello’@’localhost’ IDENTIFIED BY ‘123456’;
    CREATE USER ‘hello’@’192.168.1.101_’ IDENDIFIED BY ‘123456’;
    CREATE USER ‘hello’@’%’ IDENTIFIED BY ‘123456’;
    CREATE USER ‘hello’@’%’ IDENTIFIED BY ”;
    CREATE USER ‘hello’@’%’;
    
  • 7、查看用户

    SELECT User,Host FROM mysql.user;
    
  • 8、创建数据库、表、插入数据

    // 建立yourdb库
    create database yourdb;
    
    // 创建user表
    USE yourdb;
    CREATE TABLE user(
        username char(50) NULL,
        passwd char(50) NULL
    )ENGINE=InnoDB;
    
    // 添加数据
    INSERT INTO user(username, passwd) VALUES('name', 'passwd');
    
  • 9、编译报错:fatal error: mysql/mysql.h: No such file or directory

    sudo apt-get install libmysqlclient-dev
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值