美文网首页mysql8.0
1)linux安装mysql8.0和SQLyoq远程连接

1)linux安装mysql8.0和SQLyoq远程连接

作者: 哥斯拉啊啊啊哦 | 来源:发表于2019-08-19 23:53 被阅读0次
    下载源码包
    wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.15-linux-glibc2.12-x86_64.tar.xz
    
    xz -d mysql-8.0.15-linux-glibc2.12-x86_64.tar.xz
    tar xf mysql-8.0.15-linux-glibc2.12-x86_64.tar
    mv mysql-8.0.15-linux-glibc2.12-x86_64  /usr/local/mysql 
    
    进入mysql目录
    cd /usr/local/mysql
    
    创建用于登录mysql的用户
    adduser mysql
    
    创建3个文件夹,data日志存储目录,sql_log日志存储目录,undo目录
    mkdir data sql_log undo
    
    将文件夹权限赋给mysql用户
    chown mysql:mysql -R data/ sql_log/ undo/
    
    配置mysql信息
    vi /etc/my.cnf
    将内容全部删除,替换成以下内容
    
    [client]
    port            = 3306
    socket          = /usr/local/mysql/data/mysql.sock
    [mysqld]
    # Skip #
    skip_name_resolve              = 1
    skip_external_locking          = 1 
    skip_symbolic_links     = 1
    # GENERAL #
    user = mysql
    default_storage_engine = InnoDB
    character-set-server = utf8
    socket  = /usr/local/mysql/data/mysql.sock
    pid_file = /usr/local/mysql/data/mysqld.pid
    basedir = /usr/local/mysql
    port = 3306
    bind-address = 0.0.0.0
    explicit_defaults_for_timestamp = off
    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
    #read_only=on
    # MyISAM #
    key_buffer_size                = 32M
    #myisam_recover                 = FORCE,BACKUP
    
    # undo log #
    innodb_undo_directory = /usr/local/mysql/undo
    innodb_undo_tablespaces = 8
    
    # SAFETY #
    max_allowed_packet             = 100M
    max_connect_errors             = 1000000
    sysdate_is_now                 = 1
    #innodb = FORCE
    #innodb_strict_mode = 1
    secure-file-priv='/tmp'
    default_authentication_plugin='mysql_native_password'
    # Replice #
     server-id = 1001
     relay_log = mysqld-relay-bin
     gtid_mode = on
     enforce-gtid-consistency
     log-slave-updates = on
     master_info_repository =TABLE
     relay_log_info_repository =TABLE
    
    
    # DATA STORAGE #
     datadir = /usr/local/mysql/data/
     tmpdir = /tmp
     
    # BINARY LOGGING #
     log_bin = /usr/local/mysql/sql_log/mysql-bin
     max_binlog_size = 1000M
     binlog_format = row
     binlog_expire_logs_seconds=86400
    # sync_binlog = 1
    
     # CACHES AND LIMITS #
     tmp_table_size                 = 32M
     max_heap_table_size            = 32M
     max_connections                = 4000
     thread_cache_size              = 2048
     open_files_limit               = 65535
     table_definition_cache         = 4096
     table_open_cache               = 4096
     sort_buffer_size               = 2M
     read_buffer_size               = 2M
     read_rnd_buffer_size           = 2M
    # thread_concurrency             = 24
     join_buffer_size = 1M
    # table_cache = 32768
     thread_stack = 512k
     max_length_for_sort_data = 16k
    
    
     # INNODB #
     innodb_flush_method            = O_DIRECT
     innodb_log_buffer_size = 16M
     innodb_flush_log_at_trx_commit = 2
     innodb_file_per_table          = 1
     innodb_buffer_pool_size        = 256M
     #innodb_buffer_pool_instances = 8
     innodb_stats_on_metadata = off
     innodb_open_files = 8192
     innodb_read_io_threads = 16
     innodb_write_io_threads = 16
     innodb_io_capacity = 20000
     innodb_thread_concurrency = 0
     innodb_lock_wait_timeout = 60
     innodb_old_blocks_time=1000
     innodb_use_native_aio = 1
     innodb_purge_threads=1
     innodb_change_buffering=all
     innodb_log_file_size = 64M
     innodb_log_files_in_group = 2
     innodb_data_file_path  = ibdata1:256M:autoextend
     
     innodb_rollback_on_timeout=on
     # LOGGING #
     log_error                      = /usr/local/mysql/sql_log/mysql-error.log
     # log_queries_not_using_indexes  = 1
     # slow_query_log                 = 1
      slow_query_log_file            = /usr/local/mysql/sql_log/slowlog.log
    
     # TimeOut #
     #interactive_timeout = 30
     #wait_timeout        = 30
     #net_read_timeout = 60
    
    [mysqldump]
    quick
    max_allowed_packet = 100M
    
    [mysql]
    no-auto-rehash
    # Remove the next comment character if you are not familiar with SQL
    #safe-updates
    
    [myisamchk]
    key_buffer_size = 256M
    sort_buffer_size = 256M
    read_buffer = 2M
    write_buffer = 2M
    
    [mysqlhotcopy]
    interactive-timeout
    
    保存退出
    注意要将my.cnf权限设置为644,不然初始化时mysql会认为该文件不安全而忽略该文件
    
    编辑 /etc/profile,添加mysql启动路径 //
    vi /etc/profile
    在底部添加
    export PATH=$PATH:/usr/local/mysql/bin
    保存退出
    更新配置信息
    source /etc/profile
    可以输出 echo $PATH 查看是否添加成功
    
    返回mysql目录,用mysqld命令初始化mysql 
    --user:用户
    --basedir:安装目录
    --datadir:数据库存储路径
    
    cd /usr/local/mysql
    mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
    
    初始后就可以启动mysql服务
    
    cd support-files
    cp mysql.server /etc/init.d/mysqld
    
    启动服务
    /etc/init.d/mysqld start 
    启动成功显示:Starting MySQL...... SUCCESS! 
    ps -ef | grep mysql 查看mysql服务,如下图示
    
    成功的图示
    mysql8.0之后,root的密码得去mysql-error.log中查询
    cd /usr/local/mysql/sql_log/
    grep password mysql-error.log
    
    如下图示 
    
    登录mysql
    mysql -uroot -pgy*D2lpwpHYa
    重设root密码
    alter user root@localhost identified by '密码'
    或者 
    alter user user() identified by '密码'
    
    创建远程登录用户 192.168.0.%:意思是以192.168.0开头的ip地址都可以用这个账号登录
    create user mysql@'192.168.0.%' identified by '123456';
    
    赋予权限 all privileges 所有权限,  *.* 所有数据库
    这里我是为了方便,实际这样不安全,生产环境不这样设置
    grant all privileges *.* on mysql@'192.168.0.%';
    
    刷新权限
    flush privileges;
    

    下载mysql的图形化管理工具SQLyog
    https://pan.baidu.com/s/1M1ulKx9V2huHFw8-MbsE0A
    下载安装后打开如下图


    输入虚拟机上linux的地址,登录数据库的用户名,数据库用户密码,连接
    虚拟机上linux的ip地址可以通过ip addr命令查看

    有时候连接不上,可能是linux的防火墙没有把端口打开firewall-cmd --query-port=3306/tcp // 查看3306有没开
    firewall-cmd --add-port=3306/tcp --permanent // 添加3306端口
    firewall-cmd --reload // 重新载入添加的端口
    firewall-cmd --query-port=3306/tcp // 查看有没开启成功
    防火墙相关参考: https://blog.csdn.net/realjh/article/details/82048492

    相关文章

      网友评论

        本文标题:1)linux安装mysql8.0和SQLyoq远程连接

        本文链接:https://www.haomeiwen.com/subject/vfyysctx.html