zoukankan      html  css  js  c++  java
  • mysql/MariaDB 搭建后创建密码及开启远程

    创建密码:

    mysqladmin -u root -p password 123

    MariaDB [(none)]> use mysql
    MariaDB [mysql]> update user set password=password("123456")where user='root';
    Query OK, 0 rows affected (0.00 sec)
    Rows matched: 4 Changed: 0 Warnings: 0
    MariaDB [mysql]> flush privileges;
    Query OK, 0 rows affected (0.00 sec)

    开启远程服务:

       查看user表:可以发现表中没有开启远程的服务 %   |  root

    mysql> use mysql;
    Database changed
    mysql> select host,user,password from user;
    +--------------+------+-------------------------------------------+
    | host         | user | password                                  |
    +--------------+------+-------------------------------------------+
    | localhost    | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
    | 127.0.0.1    | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
    +--------------+------+-------------------------------------------+
    2 rows in set (0.00 sec)

    实现远程连接(授权法):

    将host字段的值改为%就表示在任何客户端机器上能以root用户登录到mysql服务器,建议在开发时设为%。   
    update user set host = ’%’ where user = ’root’;        将权限改为ALL PRIVILEGES

    MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '12345' WITH GRANT OPTION;
    Query OK, 0 rows affected (0.00 sec)
    \ MYSQL版本的命令用这个命令:( MYSQL > update user set host='%' where user='root';
    MariaDB [(none)]> flush privileges;
    Query OK, 0 rows affected (0.00 sec) mysql
    > select host,user,password from user;

    +-----------+------+-------------------------------------------+
    | host      | user | password                                  |
    +-----------+------+-------------------------------------------+
    | localhost | root | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
    | 127.0.0.1 | root | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
    | ::1       | root | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
    | localhost |      |                                           |
    | %         | root | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
    +-----------+------+-------------------------------------------+
    5 rows in set (0.00 sec)

    这样机器就可以以用户名root密码远程访问该机器上的MySql.

    创建数据库(在root权限下)
    create database mydb;
    //授权admin用户拥有mydb数据库的所有权限。
    >grant all privileges on mydb.* to admin@localhost identified by 'admin';
    //刷新系统权限表
    mysql>flush privileges;

    删除用户。
    @>mysql -u root -p
    @>密码
    mysql>DELETE FROM user WHERE User="admin" and Host="localhost";
    mysql>flush privileges;
    //删除用户的数据库
    mysql>drop database mydb;

    修改指定用户密码。
    @>mysql -u root -p
    @>密码
    mysql>update mysql.user set password=password('新密码') where User="admin" and Host="localhost";

    mysql>flush privileges;

     

  • 相关阅读:
    解释DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci
    MySQL性能优化
    MySQL中的binlog相关命令和恢复技巧
    保障MySQL安全的14个最佳方法
    MySQL忘记root密码的解决方案
    MySQL利用binlog来恢复数据库
    MySQL命令mysqldump参数大全
    MySQL REPLACE替换输出
    MySQL -A不预读数据库信息(use dbname 更快)
    MySQL 慢查询配置
  • 原文地址:https://www.cnblogs.com/kaneyang/p/9116057.html
Copyright © 2011-2022 走看看