centos 安装 mysql

来源:互联网 发布:淘宝店铺多久才能有钻 编辑:程序博客网 时间:2024/06/10 19:07

yum安装mysql

下载mysql

cd /usr/localmkdir softcd soft
wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install mysql-community-server
service mysqld restart
vim /etc/my.cnf

补充以下内容

[client]default-character-set=utf8[mysql]default-character-set=utf8[mysqld]init_connect='SET collation_connection = utf8_unicode_ci'init_connect='SET NAMES utf8'character-set-server=utf8collation-server=utf8_unicode_ciskip-character-set-client-handshake

安装完成,接下来配置用户(默认安装后没有密码)

mysql -u root

查看当前用户

select user,host from mysql.user;
delete from mysql.user where user='';

创建用户

CREATE USER 'username'@'localhost' IDENTIFIED BY 'password'; 

创建数据库

create database `test` default character set utf8 collate utf8_general_ci;

给用户权限

grant all privileges on seckill.* to seckill@'%' identified by 'seckill' with grant option;

刷新权限

flush privileges;

设置root密码

set password for root@localhost=password('123456');set password for root@127.0.0.1=password('123456');

导入.sql

use test;source /usr/local/test.sql;select * from test\G;

删除root 远程用户

use mysql;select host,user from user where user='root';delete from user where user='root' and host='%';flush privileges;select host,user from user where user='root';
原创粉丝点击