安装

官方教程:MySQL :: MySQL 5.7 Reference Manual :: 2.2 Installing MySQL on Unix/Linux Using Generic Binaries

登录

参考官方教程安装之后,命令行执行登录数据库,输入初始化时得到的随机密码。

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

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> 

以上显示即为登录成功

修改root账号的密码

两种方法

SET PASSWORD = PASSWORD('123456');

创建普通用户并授予权限

参考教程: MySQL创建用户与授权 - 简书 (jianshu.com)

创建用户

创建一个名为aaa密码为aaacccbbb可从任意远程主机(%)登陆的用户

CREATE USER 'aaa'@'%' IDENTIFIED BY 'aaacccbbb';

修改用户密码

SET PASSWORD FOR 'aaa'@'%' = PASSWORD ('newpwd');

授予权限

常用的权限类型有以下几种: all privileges:所有权限。 select:读取权限。 create:创建权限。 delete:删除权限。 update:更新权限。 drop:删除数据库、数据表权限。

允许aaa用户从任意远程主机(%)登陆时可以拥有adb数据库(数据库可不存在)中所有表格(*)的所有的权限

GRANT all ON adb.* TO 'aaa'@'%';

收回权限

revoke all on adb.* from "aaa"@"%";

配置MySQL软件

配置监听端口等信息

查看mysqld会读取的配置文件地址

# mysqld --verbose --help | grep nf
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf

在这些配置文件中配置可选项

[mysqld]
port=11196 # 必须再mysqld下

重启mysqld

重置(假设你已经做过安装的所有步骤)

删除数据库

删除data/目录

执行

bin/mysqld --initialize --user=mysql

初始化数据库,完成会输出随机root密码

之后参考新装