• Ubuntu安装Mysql数据库


    1、首先查看Ubuntu中是否安装过mysql,使用如下命令。

    dpkg -l | grep mysql

    若没有安装则不会出现任何提示,如下图是安装过的。

    2、安装mysql-server

    sudo apt install mysql-server

    3、 再次验证是否安装mysql,上面有截图

    dpkg -l | grep mysql

    root@Eth002:/home/caojun/FISCO/WeBASE-Node-Manager# dpkg -l | grep mysql
    ii  mysql-client-5.7                       5.7.40-0ubuntu0.18.04.1                   amd64        MySQL database client binaries
    ii  mysql-client-core-5.7                  5.7.40-0ubuntu0.18.04.1                   amd64        MySQL database core client binaries
    ii  mysql-common                           5.8+1.0.4                                 all          MySQL database common files, e.g. /etc/mysql/my.cnf
    ii  mysql-server                           5.7.40-0ubuntu0.18.04.1                   all          MySQL database server (metapackage depending on the latest version)
    ii  mysql-server-5.7                       5.7.40-0ubuntu0.18.04.1                   amd64        MySQL database server binaries and system database setup
    ii  mysql-server-core-5.7                  5.7.40-0ubuntu0.18.04.1                   amd64        MySQL database server binaries

     该命令也可以进行验证

    netstat -tap | grep mysql

     在控制台输入下面的命令进行登录

    mysql -u root -p

     查看数据库

    show databases;

    创建数据库,直接复制即可,创建一个node的数据库。

    CREATE DATABASE IF NOT EXISTS node DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

     

     exit退出控制台

     初始化mysql数据库,退出mysql控制台后使用如下命令

    mysql_secure_installation

     下面会出现一些选项配置,可以按照自己需要进行配置

    1、首先是安装验证插件,选择N

     2、设置root的密码,重复输入两次

     3、删除匿名账户

    4、删除默认的测试数据库

    5、刷新授权的

     6、查看mysql运行状态

    systemctl status mysq

     7、配置mysql远程访问机制,注销这一行(43行),保存退出

    vim /etc/mysql/mysql.conf.d/mysqld.cnf

     在[mysqld]里面添加 skip-grant-tables

     8、进行mysql控制台进行刷新权限,如下命令按照顺序执行即可

    mysql -u root -p
    grant all on *.* to root@'%' identified by '123456' with grant option;
    flush privileges;
    exit
    systemctl restart mysql
    systemctl status mysql

     9、远程连接,在另外一台电脑上面进行远程连接测试,输入mysql数据库电脑的ip及数据库3306端口、用户名、密码

     这里就是新建的数据库

    附上:

    1. root@Eth002:/home/caojun/FISCO/WeBASE-Node-Manager/dist/script# mysql_secure_installation
    2. Securing the MySQL server deployment.
    3. Connecting to MySQL using a blank password.
    4. VALIDATE PASSWORD PLUGIN can be used to test passwords
    5. and improve security. It checks the strength of password
    6. and allows the users to set only those passwords which are
    7. secure enough. Would you like to setup VALIDATE PASSWORD plugin?
    8. Press y|Y for Yes, any other key for No: N
    9. Please set the password for root here.
    10. New password:
    11. Re-enter new password:
    12. By default, a MySQL installation has an anonymous user,
    13. allowing anyone to log into MySQL without having to have
    14. a user account created for them. This is intended only for
    15. testing, and to make the installation go a bit smoother.
    16. You should remove them before moving into a production
    17. environment.
    18. Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
    19. Success.
    20. Normally, root should only be allowed to connect from
    21. 'localhost'. This ensures that someone cannot guess at
    22. the root password from the network.
    23. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n
    24. ... skipping.
    25. By default, MySQL comes with a database named 'test' that
    26. anyone can access. This is also intended only for testing,
    27. and should be removed before moving into a production
    28. environment.
    29. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : n
    30. ... skipping.
    31. Reloading the privilege tables will ensure that all changes
    32. made so far will take effect immediately.
    33. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
    34. Success.
    35. All done!

  • 相关阅读:
    Vue系列(一)之 Vue入门,Vue的生命周期以及前后端分离介绍
    Java 静态代理和动态代理
    【React路由】编程式路由导航和withRouter的使用——push replace
    Java中的Monad设计模式及其实现
    Linux开发工具的使用(vim、gcc/g++ 、make/makefile)
    原生input使用+v-model在input中使用
    C# yolov8 OpenVINO 同步、异步接口视频推理
    航天联志Aisino-AISINO26081R服务器通过调BIOS用U盘重新做系统(windows系统通用)
    宠物网页作业HTML 大一作业HTML宠物网页作业 web期末大作业HTML 动物网页作业HTML HTML制作宠物网页作业css
    2023年【四川省安全员A证】复审考试及四川省安全员A证考试试题
  • 原文地址:https://blog.csdn.net/weixin_46085718/article/details/127727204