linux安装MYSQL

  • 下载地址(https://dev.mysql.com/downloads),版本选择linux版本

  • 将下载的tar报上传到服务器,tar的路径其实可以自己定义,我放在/user/local/,执行命令tar -zxvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz

  • 解压之后,就需要开始安装了

  1. 解压之后的名称较长,使用mv命令修改名字,mv xxx mysq

  2. cd mysql,mkdir data

  3. groupadd mysql 建立mysql系统用户

  4. useradd -r -g mysql mysql   //useradd -r参数表示mysql用户是系统用户,不可用于登录系统

  5. cd /usr/local/ ;chown -R mysql mysql/;chgrp -R mysql mysql/;

  6.  

    ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/--datadir=/usr/local/mysql/data/
    注意:安装mysql的时候可能会出错,我的就是出错了,报错为libaio.so.1: cannot open shared object file: No such file or directory;百度了下缺少安装包了,如果错误提示和我一样则执行以下命令:yum install libaio*。

  7. 安装好的mysql提示为:
    2018-10-13T05:16:19.732268Z 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.
    2018-10-13T05:16:19.732404Z 0 [System] [MY-013169] [Server] /usr/local/mysql/mysql/bin/mysqld (mysqld 8.0.12) initializing of server in progress as process 19667
    2018-10-13T05:16:24.925271Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Hd.1kNwp1u/f
    2018-10-13T05:16:26.389288Z 0 [System] [MY-013170] [Server] /usr/local/mysql/mysql/bin/mysqld (mysqld 8.0.12) initializing of server has completed; 

  • 接下来更改配置文件了
  1. 修改 vim /usr/local/mysql/mys/support-files中  mysql.server,将databir和basedir写上自己真实的路径
  2. 修改 vim /etc/my.cnf,路径都为自己真实的路径
  3. 针对my.cnf文件中的log-error=/var/log/mariadb/mariadb.log这句话,因为没有创建该文件,所以
    mkdir /var/log/mariadb 
    touch /var/log/mariadb/mariadb.log 
    chown -R mysql:mysql /var/log/mariadb/
  4. sh /usr/local/mysql/mys/support-files/mysql.server start启动mysql
    备注:遇见报错不要慌张,已经记录到了mariadb.log,打开日志查看报错,自行百度,每个人遇到的问题都不一致
  5.  ps -ef | grep mysql就可以看到mysql程序运行
  •  关于修改密码,cat /root/.mysql_secret,查看密码,再mysql得目录下执行bin/mysql -uroot -p,黏贴密码;SET PASSWORD FOR 'root'@localhost=PASSWORD('123456');执行完毕,结束;

你可能感兴趣的:(linux安装MYSQL)