ubuntu上彻底卸载MySQL或重新安装
https://www.jianshu.com/p/974b33873bca
#查看是否存在mysql服务
service mysql status
#查看安装了MySQL的相关软件包
dpkg--get-selections |grep mysql
#卸载MySQL
apt-get remove --purge mysql-*#清除本地残留文件
apt autoclean
#清除无用依赖包(可选)
apt autoremove
#删除MySQL残留文件
rm-rf /etc/mysql /var/lib/mysql
免编译安装MySQL的方法
安装必要的依赖包
apt-getinstall libaio1
添加mysql用户 解压MySQL安装包
[root@localhost~]# groupadd mysql
[root@localhost~]# useradd -r -g mysql -s /bin/falsemysql
[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.cnf
cat> /etc/my.cnf <
[client]default-character-set =utf8mb4
port= 3306socket= /data/mysql/run/mysql.sock
[mysql]default-character-set =utf8mb4
prompt= "\u@\h \R:\m:\s [\d]>"no-auto-rehash
socket= /data/mysql/run/mysql.sock
[mysqld]
character-set-server =utf8mb4
collation-server =utf8mb4_unicode_ci
character-set-client-handshake =FALSE
server-id = 3306user=mysql
port= 3306basedir= /data/mysql
datadir= /data/mysql/data
socket= /data/mysql/run/mysql.sock
pid-file = /data/mysql/run/mysqld.pid
skip_name_resolve= 1open_files_limit= 65535back_log= 1024max_connections= 1024log-error = /data/mysql/logs/mysql-error.log
EOF
初始化MySQL
[root@localhost data]# cd/data/mysql
[root@localhost mysql]# mkdir mysql-files
[root@localhost mysql]# chown mysql:mysql mysql-files
[root@localhost mysql]# chmod750 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/data
ubuntu的unit file路径/lib/systemd/system
cat> /lib/systemd/system/mysqld.service <
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
Type=forking
PIDFile=/data/mysql/run/mysqld.pid
# Disable service start and stop timeout logic of systemdformysqld service.
TimeoutSec=0# Execute pre and post scriptsasroot
PermissionsStartOnly=true# Needed to create system tables
#ExecStartPre=/usr/bin/mysqld_pre_systemd
# Start main service
ExecStart=/data/mysql/bin/mysqld --daemonize --pid-file=/data/mysql/run/mysqld.pid $MYSQLD_OPTS
# Usethis to switchmalloc implementation
EnvironmentFile=-/etc/sysconfig/mysql
# Sets open_files_limit
LimitNOFILE= 65535Restart=on-failure
RestartPreventExitStatus=1PrivateTmp=falseEOF
配置MySQL环境变量
echo"export PATH=$PATH:/data/mysql/bin" >> /etc/profile
source/etc/profile
启动与开机启动MySQL
systemctl daemon-reload
systemctl start mysqld.service
systemctl enable mysqld.service
systemctlis-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