Under 1.Windows
Start Service
mysqld -console
or net start mysql
Close Service
mysqladmin -uroot shudown
或 net stop mysql
2.Linux under
Start Service
service mysql start
Close Service
service mysql stop
Restart Service
service restart stop
2, configure the environment variables
Variable name: MYSQL_HOME
Variable values: E: MySqlmysql-8.0.15-winx64mysql-8.0.15-winx64
path was added:% MYSQL_HOME% bin;
Note: If you need to modify some configuration, then in the current directory create their own profiles: my.ini
I'm learning more exciting content click
For example, here I will port amended as follows: 3309, the default port is 3306
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
After the change the port number, I need to restart the service to take effect.
3, generates data files
Run as administrator cmd
Enter E: MySqlmysql-8.0.15-winx64mysql-8.0.15-winx64bin under
Run: mysqld -initialize-insecure -user = mysql in E: generating a data directory MySqlmysql-8.0.15-winx64mysql-8.0.15-winx64 directory
4, start the service
Execute the command: net start mysql start mysql service, if prompted: service name is invalid, you execute the command: mysqld -install to
Click to learn more exciting content I can see this service in the list of services:
Stop the service: net stop mysql
Uninstall service: mysqld -remove mysql
Let's start using MySql:
1, link mysql :( Log in as root account)
mysql -u root -p
初始没有密码,直接enter
注意:当配置文件中将Mysql端口号更改了,则登录时需指定端口,P为大写:(这里我设置的端口为3309,,主机ip为192.168.168.152)
mysql -P 3309 -h 192.168.168.152 -u root -p
2、登录之后,修改密码,并配置远程访问
登陆成功之后修改密码(密码修改为admin):
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'admin';
或者
update mysql.user set authentication_string=password('admin') where user='root' and Host = 'localhost';
默认不允许远程访问MySQL,如果需要远程访问,下面是开启远程访问的命令:
use mysql; update user set host = '%' where user = 'root'; FLUSH PRIVILEGES;
3、基础操作
①创建数据库:
create database Temp DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
删除数据库:drop database Temp;
②创建用户:
CREATE USER ‘test’@’%’ IDENTIFIED BY ‘123456’;
CREATE USER ‘user_name’@’host’ IDENTIFIED BY ‘password’;
user_name:要创建用户的名字。
host:表示要这个新创建的用户允许从哪台机登陆,如果只允许从本机登陆,则 填 ‘localhost’ ,如果允许从远程登陆,则填 ‘%’
password:新创建用户的登陆数据库密码,如果没密码可以不写。
可执行,select * from user;查看用户列表(查看用户拥有的权限,可以看到用户很多权限都是N,因为未授权)
4、授权用户:
GRANT ALL PRIVILEGES ON Temp.* TO ‘test’@’%’;
GRANT privileges ON databasename.tablename TO ‘username’@‘host’
privileges:表示要授予什么权力,例如可以有 select , insert ,delete,update等,如果要授予全部权力,则填 ALL
databasename.tablename:表示用户的权限能用在哪个库的哪个表中,如果想要用户的权限很作用于所有的数据库所有的表,则填 *.*,*是一个通配符,表示全部。
’username‘@‘host’:表示授权给哪个用户。
5、刷新权限表
flush privileges;
执行这个命令的原因是,需要将新加入的用户写入到权限表中,即更新grant table
6、用Navicat for MySQL链接数据库:
如果链接失败的话,报错:Client does not support authentication protocol requested by server;
执行命令:
ALTER USER ‘test’@’%’ IDENTIFIED WITH mysql_native_password BY ‘123456’;
7、mysql 退出,有三种方式可退出:
mysql > exit;
mysql > quit;
mysql > q;