今天的总结
ubuntu上彻底卸载MySQL或重新安装https://www.jianshu.com/p/974b33873bca#查看是否存在mysql服务service mysql status#查看安装了MySQL的相关软件包dpkg --get-selections | grep mysql#卸载MySQLapt-get remove --purge mysql-*#清除本地残留文件apt autoclean#清除无用依赖包(可选)apt autoremove#删除MySQL残留文件rm -rf /etc/mysql /var/lib/mysql免编译安装MySQL的方法安装必要的依赖包apt-get install libaio1添加mysql用户 解压MySQL安装包[root@localhost ~]# groupadd mysql[root@localhost ~]# useradd -r -g mysql -s /bin/false mysql[root@localhost ~]# mkdir -p /data[root@localhost ~]# cd /data[root@localhost data]# tar zxf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz[root@localhost data]# ln -s mysql-5.7.23-linux-glibc2.12-x86_64 mysql[root@localhost data]# 建立存放日志等目录cd /data/mysql-5.7.23-linux-glibc2.12-x86_64/mkdir logs binlogs run删除旧配置文件rm -rf /etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf新增MySQL的配置文件/etc/my.cnfcat > /etc/my.cnf << EOF[client]default-character-set = utf8mb4port= 3306socket= /data/mysql/run/mysql.sock[mysql]default-character-set = utf8mb4prompt = " \u@\h \R:\m:\s [\d]> "no-auto-rehashsocket= /data/mysql/run/mysql.sock[mysqld]character-set-server = utf8mb4collation-server = utf8mb4_unicode_cicharacter-set-client-handshake = FALSEserver-id = 3306user= mysqlport= 3306basedir= /data/mysqldatadir= /data/mysql/datasocket= /data/mysql/run/mysql.sockpid-file = /data/mysql/run/mysqld.pidskip_name_resolve = 1open_files_limit = 65535back_log = 1024max_connections = 1024log-error = /data/mysql/logs/mysql-error.logEOF初始化MySQL[root@localhost data]# cd /data/mysql[root@localhost mysql]# mkdir mysql-files[root@localhost mysql]# chown mysql:mysql mysql-files[root@localhost mysql]# chmod 750 mysql-files[root@localhost mysql]# chown -R mysql:mysql .[root@localhost mysql]# bin/mysqld --initialize --user=mysql --basedir=/data/mysql --datadir=/data/mysql/data[root@localhost mysql]# bin/mysql_ssl_rsa_setup --datadir=/data/mysql/dataubuntu的unit file路径/lib/systemd/systemcat > /lib/systemd/system/mysqld.service << EOF[Unit]Description=MySQL ServerDocumentation=man:mysqld(8)Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.htmlAfter=network.targetAfter=syslog.target[Install]WantedBy=multi-user.target[Service]User=mysqlGroup=mysqlType=forkingPIDFile=/data/mysql/run/mysqld.pid# Disable service start and stop timeout logic of systemd for mysqld service.TimeoutSec=0# Execute pre and post scripts as rootPermissionsStartOnly=true# Needed to create system tables#ExecStartPre=/usr/bin/mysqld_pre_systemd# Start main serviceExecStart=/data/mysql/bin/mysqld --daemonize --pid-file=/data/mysql/run/mysqld.pid $MYSQLD_OPTS# Use this to switch malloc implementationEnvironmentFile=-/etc/sysconfig/mysql# Sets open_files_limitLimitNOFILE = 65535Restart=on-failureRestartPreventExitStatus=1PrivateTmp=falseEOF配置MySQL环境变量echo "export PATH=$PATH:/data/mysql/bin" >> /etc/profilesource /etc/profile启动与开机启动MySQLsystemctl daemon-reloadsystemctl start mysqld.servicesystemctl enable mysqld.servicesystemctl is-enabled mysqld用临时密码登录并修改临时密码[root@localhost ~]# grep 'temporary password' /data/mysql/logs/mysql-error.log2018-09-24T07:54:08.055154Z 1 [Note] A temporary password is generated for root@localhost: p=lXlKKrg4GJ[root@localhost ~]# mysql -urrott -p "p=lXlKKrg4GJ"mysql shell > alter user root@'localhost' identified by 'root12#$';mysql shell > \q