美文网首页
linux安装mysql

linux安装mysql

作者: 波波大人2018 | 来源:发表于2019-10-26 00:24 被阅读0次

    第一步:

    cd /opt
    cd soft
    wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
    

    或者下载到本地然后使用工具上传至服务器。新建目录存放 eg. /root/opt/soft

    第三步:

    cd /opt
    mkdir data
    mkdir data/mysql
    cd soft
     tar -zxvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz#解压缩
     mv mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz #改名字
    
    groupadd mysql #创建mysql用户组
    useradd -r -g mysql mysql #创建mysql用户
    
    #关联myql用户到mysql用户组中
    chown -R mysql:mysql  /opt/soft/mysql/
    chown -R mysql:mysql  /opt/data/mysql/
    chown -R mysql  /opt/soft/mysql/
    chown -R mysql  /opt/data/mysql
    
    chmod -R 755 /opt/soft/mysql/
    
    cd /opt/soft/mysql/bin
    
    ./mysqld --user=mysql --basedir=/opt/soft/mysql --datadir=/opt/data/mysql --initialize
    

    特别注意,执行最后一句后,会出现。localhost:后面就是临时密码

    [Note] A temporary password is generated for root@localhost: <y F:qXiX0NC
    

    第四步:修改mysql配置文件

    vi /opt/soft/mysql/support-files/mysql.server
    
    i #移到对应位置  添加以下代码
    basedir=/opt/soft/mysql
    datadir=/opt/data/mysql
    #按esc :wq 保存退出
    

    第五步:

    cp /opt/soft/mysql/support-files/mysql.server  /etc/init.d/mysqld
    chmod 755 /etc/init.d/mysqld
    
    vi /etc/my.cnf
    
    修改为:
    [client]
    no-beep
    socket =/opt/soft/mysql/mysql.sock
    # pipe
    # socket=0.0
    port=3306
    [mysql]
    default-character-set=utf8
    [mysqld]
    basedir=/opt/soft/mysql
    datadir=/opt/data/mysql
    port=3306
    pid-file=/opt/soft/mysql/mysqld.pid
    #skip-grant-tables
    skip-name-resolve
    socket = /opt/soft/mysql/mysql.sock
    character-set-server=utf8
    default-storage-engine=INNODB
    explicit_defaults_for_timestamp = true
    # Server Id.
    server-id=1
    max_connections=2000
    query_cache_size=0
    table_open_cache=2000
    tmp_table_size=246M
    thread_cache_size=300
    #限定用于每个数据库线程的栈大小。默认设置足以满足大多数应用
    thread_stack = 192k
    key_buffer_size=512M
    read_buffer_size=4M
    read_rnd_buffer_size=32M
    innodb_data_home_dir = /opt/data/mysql
    innodb_flush_log_at_trx_commit=0
    innodb_log_buffer_size=16M
    innodb_buffer_pool_size=256M
    innodb_log_file_size=128M
    innodb_thread_concurrency=128
    innodb_autoextend_increment=1000
    innodb_buffer_pool_instances=8
    innodb_concurrency_tickets=5000
    innodb_old_blocks_time=1000
    innodb_open_files=300
    innodb_stats_on_metadata=0
    innodb_file_per_table=1
    innodb_checksum_algorithm=0
    back_log=80
    flush_time=0
    join_buffer_size=128M
    max_allowed_packet=1024M
    max_connect_errors=2000
    open_files_limit=4161
    query_cache_type=0
    sort_buffer_size=32M
    table_definition_cache=1400
    binlog_row_event_max_size=8K
    sync_master_info=10000
    sync_relay_log=10000
    sync_relay_log_info=10000
    #批量插入数据缓存大小,可以有效提高插入效率,默认为8M
    bulk_insert_buffer_size = 64M
    interactive_timeout = 604800 #7*24小时
    wait_timeout = 604800 #7*24小时
    log-bin-trust-function-creators=1
    event_scheduler=1 #开启定时任务
    sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION
    #
    # include all files from the config directory
    #
    !includedir /etc/my.cnf.d
    

    第六步:

    /etc/init.d/mysqld start
    

    第七步:添加mysql目录

    vi ~/.bash_profile 
    
    增加以下一行
    PATH=$PATH:/opt/soft/mysql/bin
    
    保存关闭
    source ~/.bash_profile 
    

    第八步:进入mysql

    mysql -u root -p
    
    提示输入密码
    输入之前的临时密码

    第九步:修改mysql密码

    1、 set password=password('xxx');
    flush privileges;
    

    如果使用客户端连接出现问题,则再使用以下

    2、 update user set authentication_string=password('xxx') where user='root' and host='%'; 
    flush privileges;
    

    添加远程访问

    show databases; #查看当前的数据库
    use mysql;#使用mysql数据库
    show tables;#查看当前的数据表
    select * from user;#查看当前用户
    insert into user(Host, User, authentication_string, ssl_cipher, x509_issuer, x509_subject,
                     Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv, Reload_priv, Shutdown_priv,
                     Process_priv, File_priv, Grant_priv, References_priv, Index_priv, Alter_priv, Show_db_priv, Super_priv,
                     Create_tmp_table_priv, Lock_tables_priv, Execute_priv, Repl_slave_priv, Repl_client_priv,
                     Create_view_priv, Show_view_priv, Create_routine_priv, Alter_routine_priv, Create_user_priv,
                     Event_priv, Trigger_priv, Create_tablespace_priv) value ('%', 'root', password('root'), '', '',
                                                                              '', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y',
                                                                              'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y',
                                                                              'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y',
                                                                              'Y', 'Y', 'Y');
    flush privileges;
    

    第十步:配置阿里云安全规则和解析

    端口3306
    授权对象:0.0.0.0/0
    
    
    将备案的域名进行解析
    1.选择:将域名指向一个IPV4地址
    2.主机记录随意填
    3.记录值:填写xxxxxxx申请的ip
    

    测试。完成。。。。。。

    如果出现问题请参考

    https://www.jianshu.com/p/1293f0706343

    其他命令

    删除文件
    rm -rf /run/lock/subsys/mysql
    
    查找是素有mysql文件
    find / -name mysql 
    
    如果出现问题:
    
    useradd - r -g mysql mysql 
    

    相关文章

      网友评论

          本文标题:linux安装mysql

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