linux安装mysql

基础概念

dql -select
dml -insert update delete
ddl -create table create view
dcl -grant

安装步骤(centos7)

  • sudo yum install mysql mysql-server
    sudo yum -y install mysql-server(centos6)
  • sudo vim /etc/my.cnf
  • 修改文件增加,default-character-set = utf8
  • 启动mysql
    systemctl start mysqld

centos6启动
service mysqld start

  • 设置随系统启动
    systemctl enable mysqld
    systemctl daemon-reload

centos6中设置随系统启动
sudo chkconfig mysqld on
sudo chkconfig --list mysqld

  • 登录mysql
    mysql -u root

  • 查看用户
    select user,host from mysql.user;

  • 删除匿名用户
    delete from mysql.user where user='';

  • 刷新权限
    flush privileges;

  • 防火墙开放3306端口
    sudo vim /etc/sysconfig/iptables
    -A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT

  • 重启防火墙
    sudo systemctl restart iptables.service
    sudo service iptables restart(centos6)

  • 新建用户(7会报错,原因未知)
    insert into mysql.user(Host,User,Password) values("localhost","qinxianyun",password("qinxianyun"));

  • 创建数据库(是数字键1左边的小点,用单引号会报错) create databasemmall` default character set utf8 collate utf8_general_ci;

  • 查看权限
    select * from mysql.user \G

  • 授权
    grant all privileges on mmall.* to qinxianyun@'%' identified by 'qinxianyun' with grant option;

  • 为root用户设置密码
    set password for root@localhost=password('admin123');
    set password for [email protected]=password('admin123');
    select user,host,password from mysql.user;
    set password for [email protected]=password('admin123');

  • 授权远程访问(能访问可以不设置)
    use mysql;
    grant all privileges on . to root@'%' identified by "root";
    FLUSH RIVILEGES;

你可能感兴趣的:(linux安装mysql)