MySQL57安装与设置

安装MySQL
添加mysql源

[root@localhost ~]# rpm -ivh http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm

安装mysql
[root@localhost ~]# yum -y install mysql-community-server

启动mysql、检查状态、设置为开机自启
[root@localhost ~]# systemctl start mysqld
[root@localhost ~]# systemctl status mysqld
[root@localhost ~]# systemctl enable mysqld

第一次启动mysql,会在日志文件中生成root用户的一个随机密码,使用下面命令查看该密码
[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log

修改root用户密码
[root@localhost ~]# mysql -u root -p
Enter password:

mysql> alter user 'root'@'localhost' identified by 'p@$$w0rd';

创建数据库(数据库名为:test)
mysql> create database test;

使用test数据库
mysql> use crashcourse;

执行sql脚本(使用source命令)
mysql> source /root/MySQLCrashCourse/create.sql;
mysql> source /root/MySQLCrashCourse/populate.sql;

查看可用数据库的列表
mysql> show databases;

查看当前数据库内可用表的列表
mysql> show tables;

显示表列(表名:customers)
mysql> show columns from customers;

显示服务器错误或警告消息
mysql> show errors;
mysql> show warnings;

安全管理
不应该在日常的MySQL操作中使用root

获得所有账号列表
mysql> use mysql;
mysql> select user from user;

创建用户账号
mysql> create user test1 identified by 'p@$$w0rd';

重命名用户账号
mysql> rename user test1 to test2;

删除用户账号
mysql> drop user test;

查看用户账号权限
mysql> show grants for test;

给用户账号授予权限
mysql> grant select on crashcourse.* to test;

撤销用户权限
mysql> revoke select on crashcourse.* from test;

更改用户口令
set password for test = password('n3w p@$$w0rd');

设置自己的口令
set password = password('n3w p@$$w0rd');

汉语支持:

vi /etc/my.cnf
···
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
character-set-server = utf8
collation-server = utf8_general_ci

[client]
default-character-set = utf8

posted @ 2019-06-21 09:24  colman_cc  阅读(1492)  评论(0编辑  收藏  举报