安装mysql

[root@localhost ~]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

[root@localhost ~]# yum -y install mysql57-community-release-el7-10.noarch.rpm [root@localhost ~]# yum -y install mysql-community-server [root@localhost ~]# service mysqld status [root@localhost ~]# service mysqld start [root@localhost ~]# service mysqld stop

怎么查看安装mysql设置的密码(Mysql新手必备-Mysql安装)(1)

设置mysql用户名和密码

[root@localhost ~]# grep "password" /var/log/mysqld.log [root@localhost ~]# use mysql

mysql> use mysql mysql> show variables like 'validate_password%'

怎么查看安装mysql设置的密码(Mysql新手必备-Mysql安装)(2)

mysql> set global validate_password_policy=0; mysql> set global validate_password_length=6;

方式一: set 并设置密码永不过期 mysql> set password=password('123456'); # set设置 mysql> alter user 'root'@'localhost' password expire never; mysql> flush privileges; mysql> exit; 方式二: update用户密码 mysql> update user set password=password("123456") where user='root'; # update更新 mysql> flush privileges; mysql> exit;

首先,你必须有linux的系统root权限,可以 sudo su 然后,使用Mysql的安全模式进入 service mysqld stop(要先将mysqld添加为系统服务) mysqld_safe --skip-grant-tables & 或者 mysqld_safe --defaults-file=/etc/my.cnf --skip-grant-tables & 接着重置密码: # mysql #5.6及以前 mysql> UPDATE mysql.user SET password=password('123456') WHERE user='root'; # 5.7;mysql.user表authentication_string字段替换了password字段; mysql> UPDATE mysql.user SET authentication_string=password('123456') WHERE user='root'; mysql> flush privileges; mysql> exit;

查看与修改mysql端口

1. 查看端口,默认是3306 mysql> show global variables like 'port'; 2. 修改端口,进入my.cnf文件,添加port=2206 ,然后重启服务 [root@localhost ~] vi /etc/my.cnf [root@localhost ~] /etc/init.d/mysqld restart

创建mysql用户

create user tong identified by '123'; create user tong@localhost identified by '123'; 只能本地登录 mysql> create user tong@'192.168.206.0/255.255.255.0' identfied by '123'; 192.168.206.0/24 #网段 mysql> create user tong@'192.168.206.10' identfied by '123'; 只允许192.168.206.10该ip登录 create user tom@'%' identified by '123'; 所有能连接主机

grant select on mydb.* to tong@'localhost'; #授权查看的权限 show grants for tong\G *************************** 1. row *************************** Grants for tong@%: GRANT USAGE ON *.* TO 'tong'@'%' IDENTIFIED BY PASSWORD '*23AE809DDACAF96AF0FD78ED04B6A265E05AA257' *************************** 2. row *************************** Grants for tong@%: GRANT SELECT ON `mydb`.* TO 'tong'@'%' 远程主机授权 grant all on mydb.* to tom@'192.168.206.10' identified by '123'; grant all on mydb.* to tom@'%' identified by '123'; 授权selecet和insert权限 grant select,insert on mydb.* to jerry@'localhost' identified by '123'; 授权某个特定的表访问权限 grant select,insert on mydb.test to tom@'localhost' identified by '123';

mysql删除用户与移除用户授权

drop user tong; drop user tong@'192.168.206.10'; revoke 权限 on 库.表 from 用户@主机; revoke select on mydb.* from tong'localhost';

,