MySql数据库开始使用步骤

2020-12-06  乐帮网

mysql

当我们完成安装MYSQL后,便会添加用户和数据库来展开开发业务,这个时候我们需要后台的命令行做一系操作来满足需求。

数据库初始使用时必须修改root的密码才能使用,查询初始密码的例如下:

# grep 'temporary password' /var/log/mysqld.log

如果没有查询到,证明mysql初始化没有成功!

任务目标:添加metoo帐号密码 mypassword ,来访问新数据库 dbtest。操作如下:

# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.22

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'rootpassword';
Query OK, 0 rows affected (0.01 sec)

mysql> CREATE DATABASE IF NOT EXISTS dbtest default charset utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected, 2 warnings (0.01 sec)

mysql> create user 'metoo'@'%' identified WITH mysql_native_password by 'mypassword';
Query OK, 0 rows affected (0.01 sec)

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select host, user,plugin from user;
+-----------+------------------+-----------------------+
| host      | user             | plugin                |
+-----------+------------------+-----------------------+
| %         | metoo            | mysql_native_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
| localhost | root             | caching_sha2_password |
+-----------+------------------+-----------------------+
5 rows in set (0.00 sec)

mysql> use dbtest;
Database changed
mysql> grant all privileges on dbtest.* to 'metoo'@'%';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

至此我们任务完成,使用metoo可以远程登录成功。

MYSQL系列文章 

MySql8境配置my.cnf

MySql rpm下载地址

CentOS 卸载MySql8

CentOS 安装MySql8 离线手动安装(rpm)

CentOS8 安装MySql8yum方式

MySql数据库开始使用步骤

MySQL 创建用户命令带密码和加密规则

 MySQL8 启动报错Warning: World-writable config file '/etc/my.cnf’ is ignored

MySQL Authentication plugin 'caching_sha2_password' cannot be loaded

Windows 安装MySQL8

原创作品,禁止转载!

公众号二维码

关注我的微信公众号
在公众号里留言交流
投稿邮箱:1052839972@qq.com

庭院深深深几许?杨柳堆烟,帘幕无重数。
玉勒雕鞍游冶处,楼高不见章台路。
雨横风狂三月暮。门掩黄昏,无计留春住。
泪眼问花花不语,乱红飞过秋千去。

欧阳修

付款二维码

如果感觉对您有帮助
欢迎向作者提供捐赠
这将是创作的最大动力