热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

mysql5.7安装及设置root密码

mysql5.7安

1

增加/etc/yum.repo.d/mysql-community.repo

    [mysql56-community]
    name=MySQL 5.6 Community Server
    baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/
    enabled=1
    gpgcheck=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql


    2

    执行yum安装

      sudo yum install -y mysql-community-server


      3

      修改配置文件

        vi etc/my.cnf


          [mysqld]
          socket = data/mysql/mysql.sock
          default-time-zOne= '+8:00'
          key_buffer_size = 1024M
          max_allowed_packet = 16M
          table_open_cache = 1024
          sort_buffer_size = 128M
          read_buffer_size = 128M
          read_rnd_buffer_size = 32M
          myisam_sort_buffer_size = 364M
          myisam_max_sort_file_size = 10G
          thread_cache_size = 64
          query_cache_size= 256M
          query_cache_type=1
          query_cache_limit=2M
          innodb_thread_cOncurrency= 16
          max_cOnnections=1000
          max_connect_errors=10000
          max_heap_table_size = 64M
          tmp_table_size = 32M
          ft_min_word_len=1
          ft_stopword_file=
          delay_key_write=ALL
          tmp_table_size=800M
          tmpdir = tmp/
          skip-name-resolve
          wait_timeout = 28800
          interactive_timeout = 28800
          group_concat_max_len = 102400


          character-set-server=utf8
          server-id = 81
          binlog_format = row
          log-error=/data/mysql/2_7_81-error.log
          pid-file=/data/mysql/2_7_81.pid
          datadir = data/mysql/


          log-bin=/data/mysql/2_7_81-bin
          log-bin-index=/data/mysql/2_7_81-bin.index
          log_bin_trust_function_creators=1


          log_slave_updates
          expire_logs_days=15


          relay-log=/data/mysql/2_7_81-srelay.log
          relay_log_purge=1


          slow_query_log = 1
          slow_query_log_file=/data/mysql/2_7_81-slowquery.log
          long_query_time=10


          innodb_file_per_table=1
          innodb_write_io_threads=8
          innodb_read_io_threads=8
          innodb_lock_wait_timeout=300
          innodb_large_prefix=on


          ft_min_word_len = 1
          sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION




          [mysqldump]
          quick
          max_allowed_packet=512M
          default-character-set=utf8
          [mysql]
          no-auto-rehash
          [isamchk]
          key_buffer = 256M
          sort_buffer_size = 256M
          read_buffer = 2M
          write_buffer = 2M
          [myisamchk]
          key_buffer = 256M
          sort_buffer_size = 256M
          read_buffer = 2M
          write_buffer = 2M
          [client]
          socket = /data/mysql/mysql.sock

          主要修改datadir、socket的路径

          4

          启动mysql

            service mysqld restart


            5



            设置不用密码就可以登录

            mysql能够正常启动后,先修改/etc/my.cnf,在[mysqld]下添加skip-grant-tables,意思是数据库启动的时候 跳跃权限表的限制,不用验证密码,直接登录

              [myslqd]
              ...
              skip-grant-tables
              ...


              保存后重启服务

                service mysqld restart


                6

                登录

                  mysql -uroot -p

                  直接回车就可以登录进去

                  7

                  修改root密码

                  登录后,执行

                    update mysql.user set authentication_string=password('123456') where user= 'root';
                    FLUSH PRIVILEGES;

                    即:设置root用户的密码是123456。下次登录就可以使用密码登录。注意要将/etc/my.cnf中skip-grant-tables去掉,并重启mysqld服务

                    8

                    注意

                    通过密码登录后,可能会提示要reset用户的密码,需要执行下面重置密码的命令:

                      alter user 'root'@'localhost' identified by '123456';

                      如果执行失败,提示密码策略错误,说明当前的密码不满足默认的策略,要么修改的密码包含字母、数字、特殊字符。要么修改默认的密码策略:

                        set global validate_password.policy=0; #设置为弱口令


                        /

                        /

                        / 微信号 / 程序老哥/



                        推荐阅读
                        author-avatar
                        迷迷糊糊的Nancy
                        这个家伙很懒,什么也没留下!
                        PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
                        Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有