centos7 安装mysql

Linux

解释

命令

安装服务端

yum install mysql-community-server

启动

service mysqld start/restart

停止

service mysqld stop

CentOS7默认安装mariadb数据库:yum remove mariadb-libs.x86_64

下载Mysql源:https://dev.mysql.com/downloads/repo/yum/

         wget     https://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm

安装源:yum localinstall mysql57-community-release-el7-8.noarch.rpm

安装MySQL:yum install mysql-community-server

启动: service mysqld start

  

  或者:systemctl restart mysqld

默认密码:cat /var/log/mysqld.log | grep “password”

     或者 grep ‘temporary password‘ /var/log/mysqld.log

重置密码,查看文章

 mysql> SET PASSWORD = PASSWORD(‘123456‘);   //123456 是重置的新密码

http://blog.sina.com.cn/s/blog_a0d71a9d0102wlz3.html

设置root可以远程连接

update  mysql.`user` set Host = ‘%‘ where User = ‘root‘ and Host = ‘localhost‘;

flush privileges; 或者重启服务 sudo service mysqld restart

关闭防火墙

sudo service firewalld stop

MySQL开启general_log跟踪数据执行过程

# 设置general log保存路径

# 注意在Linux中只能设置到 /tmp 或 /var 文件夹下,设置其他路径出错

# 需要root用户才有访问此文件的权限

mysql> set global general_log_file=‘/tmp/general.log‘; 

# 开启general log模式

mysql> set global general_log=on; 

# 关闭general log模式

mysql>set global general_log=off; 

在general log模式开启过程中,所有对数据库的操作都将被记录 general.log 文件

新建用户

CREATE USER ‘imooc‘@‘%‘ IDENTIFIED BY ‘123456‘;

赋予权限

GRANT ALL PRIVILEGES ON *.* TO ‘imooc‘@‘%‘ IDENTIFIED BY ‘123456‘ WITH GRANT OPTION;

GRANT select,insert,update,delete ON *.* TO ‘imooc‘@‘%‘ IDENTIFIED BY ‘123456‘ WITH GRANT OPTION;

FLUSH PRIVILEGES;

收回权限

REVOKE ALL PRIVILEGES ON *.* FROM imooc;

FLUSH PRIVILEGES;

忘记root 密码

在 /etc/my.cnf 加入 skip-grant-tables

use mysql;

update user set authentication_string=password(‘456789‘) where user=‘root‘;

­­­

相关推荐