参考教程:https://www.cnblogs.com/brad93/p/16650780.html
【检查是否已安装过】
find / -name mysql
【快速安装开始】
groupadd mysql ;useradd -g mysql mysql;cd /usr/local/ &&wget https://nchc.dl.sourceforge.net/project/lzmautils/xz-5.2.6.tar.gz &&tar -xzvf xz-5.2.6.tar.gz &&cd xz-5.2.6 && ./configure && make && make install && cd .. && rm -rf xz-5.2.6 && rm -rf xz-5.2.6.tar.gz &&yum install -y libaio;yum install -y libaio.so.1;cd /usr/local/&&wget https://cdn.mysql.com/Downloads/MySQL-8.0/mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz &&tar Jxvf mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz &&mv mysql-8.0.30-linux-glibc2.12-x86_64 mysql &&rm -rf mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz&&cd mysql &&chown -R mysql . &&chgrp -R mysql . &&mkdir /usr/local/mysql/data
vim /etc/my.cnf 输入以下内容
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
保存后继续:
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
将生成的初始密码复制一下
chown -R root . && chown -R mysql data && /usr/local/mysql/bin/mysqld_safe --user=mysql&
回车一下,或者继续执行
./bin/mysqladmin -uroot -p password
输入复制的原密码并修改密码为123
下方指令依次手动执行:(centos8提示找不到libtinfo.so.5解决方法:ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5)
/usr/local/mysql/bin/mysql -u root -p123
use mysql;
select user,host from user;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123';
上下这两个执行有一个执行成功就可以了,忽略报错的
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123';
退出mysql三种方法:
exit;
quit;
\q;
修改密码为自定义的:(上面密码将改为123了)
./bin/mysqladmin -uroot -p password
启动mysql:/usr/local/mysql/bin/mysqld_safe --user=mysql&
登录mysql(注意路径和账号密码):/usr/local/mysql/bin/mysql -u root -p123
然后在尝试登录就可以了,还有其他问题多搜索搜索
mysql启动:service mysqld start
mysql关闭:service mysqld stop
查看mysql是否运行:ps -A | grep mysql
查看3306端口占用情况:
netstat -tunlp | grep 3306
错误代码2003:防火墙拦截(包含服务器运营商外放端口拦截)
错误码1130解决:https://www.cnblogs.com/zgqbky/p/13390360.html
依次输入下列命令:
/usr/local/mysql/bin/mysql -u root -p123 #注意路径和账号密码的正确性
use mysql;
select 'host' from user where user='root';
update user set host = '%' where user ='root';
flush privileges;
exit; #搞定离开