美文网首页
Linux下mysql8.0安装及服务启动

Linux下mysql8.0安装及服务启动

作者: 牙齿不帅 | 来源:发表于2020-06-15 22:46 被阅读0次

    1.下载mysql安装包。
    下载地址:https://dev.mysql.com/downloads/mysql/ 可以选择自己想要的类型。
    2.解压安装及运行如下:

    //解压
    [root@VM_0_15_centos home]# tar -xf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
    [root@VM_0_15_centos home]# mv mysql-8.0.20-linux-glibc2.12-x86_64 /usr/local/mysql
    [root@VM_0_15_centos home]# cd /usr/local/mysql
    [root@VM_0_15_centos home]# mkdir data
    
    //创建mysql用户,并给对应的文件夹权限
    [root@VM_0_15_centos home]# adduser mysql
    [root@VM_0_15_centos home]# chown -R mysql:mysql /user/local/mysql/
    [root@VM_0_15_centos home]# chmod -R 775 /usr/local/mysql
    
    [root@VM_0_15_centos home]# cd bin
    //初始化mysql
    [root@VM_0_15_centos bin]# ./mysqld --initalize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
    //出现错误
    ./mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory 
    //解决方法
    [root@VM_0_15_centos bin]# yum -y install numactl
    
    //再初始化成功,并生成临时密码!
    [root@VM_0_15_centos bin]# mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
    2020-06-15T13:55:59.427118Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
    2020-06-15T13:55:59.427208Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.20) initializing of server in progress as process 17608
    2020-06-15T13:55:59.434082Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
    2020-06-15T13:56:02.505867Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
    2020-06-15T13:56:05.099467Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ECUtpahf=8oe
    
    //编辑配置文件
    [root@VM_0_15_centos bin]# vim /etc/my.cnf
    [mysqld]
    port=3306
    user=mysql
    datadir=/usr/local/mysql/data
    socket=/var/lib/mysql/mysql.sock
    symbolic-links=0
    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
    
    //配置开机启动项
    [root@VM_0_15_centos bin]# cd ../support-files
    [root@VM_0_15_centos support-files]# cp mysql.server /etc/init.d/mysqld
    [root@VM_0_15_centos support-files]# chmod 755 /etc/init.d/mysqld
    [root@VM_0_15_centos support-files]# chkconfig --add mysqld
    [root@VM_0_15_centos support-files]# chkconfig --list mysqld
    
    //启动
    [root@VM_0_15_centos support-files]# ./mysql.server start --user=mysql
    Starting MySQL.Logging to '/usr/local/mysql/data/VM_0_15_centos.err'.
    . SUCCESS! 
    
    //查看进程
    [root@VM_0_15_centos support-files]# ps -ef|grep mysql
    root     19648     1  0 22:05 pts/1    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/VM_0_15_centos.pid --user=mysql
    mysql    19826 19648 14 22:05 pts/1    00:00:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysq/lib/plugin --user=mysql --log-error=VM_0_15_centos.err --pid-file=/usr/local/mysql/data/VM_0_15_centos.pid --socket=/var/lib/mysql/mysql.sock --port=3306
    root     19900 12352  0 22:05 pts/1    00:00:00 grep --color=auto mysql
    
    //修改sock的软连接,/var/lib/mysql/mysql.sock是my.cnf文件中配置的路径
    [root@VM_0_15_centos support-files]# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
    
    //配置环境变量
    [root@VM_0_15_centos support-files]# vim /etc/profile
    ...
    #配置mysql环境变量
    MYSQL_HOME=/usr/local/mysql
    PATH=$PATH:$MYSQL_HOME/bin
    export PATH MYSQL_HOME
    ...
    [root@VM_0_15_centos support-files]# source /etc/profile
    
    

    登录mysql,修改默认root密码

    [root@VM_0_15_centos support-files]# mysql -uroot -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 13
    Server version: 8.0.20
    Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    mysql>  
    //修改默认用户密码
    mysql> alter user 'root'@'localhost' identified by 'yourpass';
    Query OK, 0 rows affected (0.02 sec)
    mysql> 
    //查看用户host地址
    mysql> select user,host from mysql.user;
    +------------------+-----------+
    | user             | host      |
    +------------------+-----------+
    | mysql.infoschema | localhost |
    | mysql.session    | localhost |
    | mysql.sys        | localhost |
    | root             | localhost |
    +------------------+-----------+
    4 rows in set (0.01 sec)
    
    mysql> 
    mysql> use mysql;
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    Database changed
    mysql> 
    //修改root用户host为任何主机
    mysql> update user set host='%' where user='root';
    Query OK, 1 row affected (0.04 sec)
    Rows matched: 1  Changed: 1  Warnings: 0
    mysql> 
    mysql> flush privileges;
    Query OK, 0 rows affected (0.01 sec)
    mysql> 
    

    相关文章

      网友评论

          本文标题:Linux下mysql8.0安装及服务启动

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