linux下安装配置mysql

时间:2020-12-24 16:11:04
  1. 安装mysql
    yum install mysql-server
    启动mysql service mysqld start
    停止mysql service mysqld stop
    重启mysql service mysqld restart

  2. 配置mysql

    • 修改root密码
      /usr/bin/mysqladmin -u root password 'new password'
    • 修改字符编码
      vim /etc/my.cnf
      [client]
      default-character-set=utf8
      [mysqld]
      character-set-server=utf8
      [mysql]
      default-character-set=utf8
    • 修改使其不区分表名大小写(注意在[mysqld]添加])
      lower_case_table_names=1
    • 配置远程访问(任何主机通过root访问)
      登入到mysql再执行以下命令
      grant all on *.* to root@'%' identified by 'root-password'
      flush privileges

      别忘记重启mysql
  3. 移动数据库
    mysqldump -u root -p --database databaseName |mysql -h 118.89.165.181 -u root -p
  4. 更改root密码
    my.cnf的[mysqld]加入skip-grant-tables(跳过验证)
    update user set password=password('zycx') where user = 'root'
    或则update user set authentication_string=password('zycx')where user = 'root' (mysql5.7)
    flush privileges
    my.cnf中去除skip-grant-tables 这句