暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

centos 安装mysql8

数据库这点小事 2019-11-06
1320

1.下载mysql

    wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.12-linux-glibc2.12-x86_64.tar

    2.解压mysql

      tar -xvf mysql-8.0.12-linux-glibc2.12-x86_64.tar

      再解压

        tar xvJf mysql-8.0.12-linux-glibc2.12-x86_64.tar.xz

        修改名称

          mv mysql-8.0.12-linux-glibc2.12-x86_64 mysql

          3.安装mysql

           

          3.1 增加mysql用户

          创建mysql用户,组:

            groupadd mysql
            useradd -g mysql mysql
            passwd mysql

            3.2 添加文件夹和所需文件

              mkdir -p appl/mysql/data
              mkdir -p appl/mysql/run
              mkdir -p appl/mysql/log
              touch appl/mysql/log/mysql-error.log
              chown -R mysql:mysql appl/mysql

              3.3 初始化mysql

              如果无异常情况日志如下可以看到mysql默认会生成root账号和密码

                /appl/mysql/bin/mysqld --initialize --user=mysql --basedir=/appl/mysql/ --datadir=/appl/mysql/data/ --lower-case-table-names=1

                3.4 修改配置文件vim/etc/my.cnf

                  # The following options will be passed to all MySQL clients
                  [client]
                  #password = your_password
                  port = 3306
                  socket = /tmp/mysql.sock
                  #default-character-set = utf8
                  host = localhost
                  user = root
                  password = root001
                  # The MySQL server
                  [mysqld]
                  port = 3306
                  socket = /tmp/mysql.sock
                  skip-external-locking
                  skip-name-resolve
                  pid-file = /appl/mysql/run/mysqld.pid
                  datadir = /appl/mysql/data
                  basedir = /appl/mysql
                  default-time-zone='+08:00'

                  key_buffer_size = 128M
                  max_allowed_packet = 32M
                  table_open_cache = 512
                  sort_buffer_size = 8M
                  net_buffer_length = 8K
                  read_buffer_size = 8M
                  read_rnd_buffer_size = 8M
                  myisam_sort_buffer_size = 128M
                  character_set_server=utf8
                  default-storage-engine = InnoDB
                  max_connections = 1024
                  innodb_flush_method = O_DIRECT
                  innodb_buffer_pool_size = 1G
                  innodb_file_per_table = 1
                  interactive_timeout = 100
                  innodb_log_buffer_size = 8M
                  innodb_log_file_size = 64M
                  innodb_flush_log_at_trx_commit = 2
                  wait_timeout = 100
                  #table_cache = 2048
                  thread_cache_size = 512
                  relay_log_purge=0
                  lower_case_table_names=1
                  sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"
                  #log =/appl/mysql/log/mysql.log
                  log_error = /appl/mysql/log/mysql-error.log
                  #log_queries_not_using_indexes = 1
                  #slow_query_log = 1
                  #slow_query_log_file = appl/mysql/log/mysql-slow.log
                  # binary logging is required for replication
                  log-bin=mysql-bin-9110
                  replicate-ignore-db=mysql
                  # binary logging format - mixed recommended
                  binlog_format=mixed
                  # but will not function as a master if omitted
                  server-id = 9110
                  innodb_data_home_dir = /appl/mysql/data
                  #rpl_semi_sync_master_enabled=1
                  #rpl_semi_sync_master_timeout=1000
                  #rpl_semi_sync_slave_enabled=1
                  tmp_table_size = 128M
                  max_heap_table_size = 128M
                  innodb_buffer_pool_instances = 10
                  innodb_read_io_threads = 8
                  innodb_write_io_threads = 8
                  innodb_thread_concurrency = 0
                  innodb_purge_threads = 1
                  #innodb_file_format = Barracuda
                  innodb_use_native_aio = 1
                  innodb_stats_on_metadata = 0
                  [mysqldump]
                  quick
                  max_allowed_packet = 64M
                  default-character-set = utf8
                  [mysql]
                  no-auto-rehash
                  # Remove the next comment character if you are not familiar with SQL
                  #safe-updates
                  [myisamchk]
                  key_buffer_size = 128M
                  sort_buffer_size = 128M
                  read_buffer = 2M
                  write_buffer = 2M
                  [mysqlhotcopy]
                  interactive-timeout
                  [mysqld_safe]
                  err-log=/appl/mysql/log/mysql-error.log
                  pid-file=/appl/mysql/run/mysqld.pid


                   

                  3.5 配置mysql服务,启动mysql

                    cp /appl/mysql/support-files/mysql.server /etc/init.d/mysqldservice mysqld  start


                     

                    3.6配置全局环境变量

                      vi /etc/profile
                      PATH=/appl/mysql/bin:/appl/mysql/lib:$PATH
                      Source /etc/profile


                       

                      3.7 修改默认账户密码

                      mysql -uroot -p

                      输入安装时打印出的随机密码,登录

                        ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root001';


                         

                        4.创建mysql用户

                        创建用户,授予权限

                          CREATE USER 'username'@'ip.%' identified with mysql_native_password by 'passwd';
                          GRANT ALL PRIVILEGES ON db.* to 'username'@'ip.%' WITH GRANT OPTION;
                          flush privileges;


                          5.mysql忘记密码重置

                          免密码登陆,

                          vim /etc/my.cnf

                          在【mysqld】模块添加:skip-grant-tables

                          重启mysql服务: service mysqld restart

                          登陆mysqlmysql -u root -p //提示输入密码时直接敲回车选择mysql数据库

                          root密码置空,update user set authentication_string = '' where user = 'root';

                          去重my.cnf中的skip-grant-tables并重启mysql服务登陆mysql

                          ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';(注意,这里mysql默认加密用的shanavicat连接会提示authentication plugin 'caching_sha2_password',可使用ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';)


                          文章转载自数据库这点小事,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

                          评论