1.命令安装
sudo apt-get install mysql-server //服务端
apt-get isntall mysql-client //客户端
2.查看是否安装成功.
sudo netstat -tap | grep mysql
3.登录mysql
mysql -u root -p //-u代表用户,-p表示密码.
4.查询当前数据库的用户.
select user,host from mysql.user;
5.删除用户
delete from mysql.user where user ='';
flush privileges; // 刷新生效.
6.修改密码
set password for root@localhost=password('mima');
windows 命令修改
7.添加新的用户.
insert into mysql.user(Host,user,password) values ('localhost','name',password('mima'));
8.给用户赋予权限.
grant all #(可以是,insert ,update)
privileges on mmall.* to youruserName@localhost identified by 'yourmima'
centos6.9 安装mysql 5.7
# mysql 下载地址 https://downloads.mysql.com/archives/community/
# 选择版本 https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz
1. 解压移动到文件夹
mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql
# 配置环境变量 添加 vi /etc/profile
export PATH=${PATH}:/usr/local/mysql/bin
2. 在/usr/local/mysql目录下创建data目录
mkdir /usr/local/mysql/data
3. 更改mysql目录下所有的目录及文件夹所属的用户组和用户,以及权限
[root@localhost /]# chown -R mysql:mysql /usr/local/mysql
[root@localhost /]# chmod -R 755 /usr/local/mysql
4. 编辑配置文件 my.cnf,添加配置如下 find / -name "my.cnf" //找出所有的my.cnf配置文件
# [root@localhost bin]# vi /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data
port=3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=600
innodb_file_per_table=1
lower_case_table_names=1
5. 编译安装并初始化mysql,务必记住初始化输出日志末尾的密码, 初次登录时候使用
cd /usr/local/mysql/bin
./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
安装参成功后打印, 最后一段为临时密码
2020-08-26T07:24:08.353242Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-08-26T07:24:08.353671Z 1 [Note] A temporary password is generated for root@localhost: Xbr1L%ei7=gC
测试启动mysql服务器
[root@localhost /]# /usr/local/mysql/support-files/mysql.server start
#查询服务
ps -ef|grep mysql | grep -v grep
ps -ef|grep mysqld | grep -v grep
#结束进程
kill -9 PID
6. 添加软连接,并重启mysql服务
[root@localhost /]# ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[root@localhost /]# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
[root@localhost /]# service mysql restart
7. 登录mysql,修改密码(密码为步骤5生成的临时密码)
[root@localhost /]# mysql -u root -p
Enter password:
mysql>set password for root@localhost = password('yourpass');
# 密码过期的情况处理
查看所有用户
use mysql;
select Host,User from user;
将set password for 'root'@'localhost'=password('MyNewPass4!'); 代码中的localhost修改%,与数据库Host字段值一致
set password for 'root'@'%'=password('yourpass');
备注
配置文件添加 skip-grant-tables 跳过密码验证
8. 开放远程连接
mysql>use mysql;
msyql>update user set user.Host='%' where user.User='root';
mysql>flush privileges;
9. 设置开机自动启动
1、将服务文件拷贝到init.d下,并重命名为mysql
[root@localhost /]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
2、赋予可执行权限
[root@localhost /]# chmod +x /etc/init.d/mysqld
3、添加服务
[root@localhost /]# chkconfig --add mysqld
4、显示服务列表
[root@localhost /]# chkconfig --list
windows 安装官方压缩包绿色版mysql
安装包下载完之后,bin/ 执行 mysqld -install命令安装服务。执行 net start mysql 命令启动服务