Centos 安装 MySQL5.7
MySQL
安装版本:5.7.35
#获取压缩包
wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz
#解压
tar -zxvf mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz
#重命名
mv mysql-5.7.35-linux-glibc2.12-x86_64 /usr/local/mysql
#创建data目录
mkdir /usr/local/mysql/data
#创建MySQL的用户
groupadd mysql
useradd -r -g mysql mysql
#赋予权限
chown -R mysql:mysql /usr/local/mysql
chmod -R 755 /usr/local/mysql
#进入bin目录,初始化(记住临时密码,后面需要)
cd /usr/local/mysql/bin
./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
#创建配置文件
vim /etc/my.cnf
##内容
[mysqld]
datadir=/usr/local/mysql/data
port = 3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=400
innodb_file_per_table=1
lower_case_table_names=1
character_set_server=utf8
#启动
/usr/local/mysql/support-files/mysql.server start
#添加软连接并测试
ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
service mysql restart
#用刚才的临时密码,登录。修改新密码
mysql -u root -p
set password for root@localhost = password('123456');
#开启远程连接!用Navicat界面管理软件去连接
use mysql;
update user set user.Host='%' where user.User='root';
flush privileges;
#放行MySQL端口
firewall-cmd --permanent --add-service=mysql
firewall-cmd --reload
报错
# service mysql restart 启动报错:
# 来源:http://t.csdnimg.cn/HW8zk
# 如果启动时出错:Failed to start mysql.service: Unit mysql.service is masked
# 原因可能是之前使用apt-get 安装过mysql,服务被标记过,解除后即可启动:
systemctl unmask mysql.service
#报错2
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
#解决
root@10-120-131-116:/usr/lib# find / -name 'libncurses*'
/usr/share/doc/libncursesw6
/usr/share/doc/libncurses6
/usr/lib/x86_64-linux-gnu/libncursesw.so.6.3
/usr/lib/x86_64-linux-gnu/libncurses.so.5
/usr/lib/x86_64-linux-gnu/libncurses.so.6
/usr/lib/x86_64-linux-gnu/libncurses.so.6.3
/usr/lib/x86_64-linux-gnu/libncursesw.so.6
/snap/core20/1974/usr/lib/x86_64-linux-gnu/libncurses.so.6
/snap/core20/1974/usr/lib/x86_64-linux-gnu/libncurses.so.6.2
/snap/core20/1974/usr/lib/x86_64-linux-gnu/libncursesw.so.6
/snap/core20/1974/usr/lib/x86_64-linux-gnu/libncursesw.so.6.2
/snap/core20/1974/usr/share/doc/libncurses6
/snap/core20/1974/usr/share/doc/libncursesw6
/var/lib/dpkg/info/libncursesw6:amd64.symbols
/var/lib/dpkg/info/libncursesw6:amd64.md5sums
/var/lib/dpkg/info/libncursesw6:amd64.list
/var/lib/dpkg/info/libncurses6:amd64.md5sums
/var/lib/dpkg/info/libncursesw6:amd64.shlibs
/var/lib/dpkg/info/libncurses6:amd64.shlibs
/var/lib/dpkg/info/libncurses6:amd64.symbols
/var/lib/dpkg/info/libncursesw6:amd64.triggers
/var/lib/dpkg/info/libncurses6:amd64.list
/var/lib/dpkg/info/libncurses6:amd64.triggers
root@10# cd /usr/lib/x86_64-linux-gnu
root@10# ln -s libncurses.so.6.3 libncurses.so.5
#报错3
mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
#解决:
root@10:/usr/lib/x86_64-linux-gnu# find / -name "libtinfo*"
/usr/share/doc/libtinfo6
/usr/lib/x86_64-linux-gnu/libtinfo.so.6
/usr/lib/x86_64-linux-gnu/libtinfo.so.6.3
/snap/core20/1974/usr/lib/x86_64-linux-gnu/libtinfo.so.6
/snap/core20/1974/usr/lib/x86_64-linux-gnu/libtinfo.so.6.2
/snap/core20/1974/usr/share/doc/libtinfo6
/var/lib/dpkg/info/libtinfo6:amd64.symbols
/var/lib/dpkg/info/libtinfo6:amd64.md5sums
/var/lib/dpkg/info/libtinfo6:amd64.list
/var/lib/dpkg/info/libtinfo6:amd64.shlibs
/var/lib/dpkg/info/libtinfo6:amd64.triggers
root@10-120-131-116:/usr/lib/x86_64-linux-gnu# cd /usr/lib/x86_64-linux-gnu
root@10-120-131-116:/usr/lib/x86_64-linux-gnu# ln -s libtinfo.so.6 libtinfo.so.5
root@10-120-131-116:/usr/lib/x86_64-linux-gnu# mysql status
root@10# cd /usr/lib/x86_64-linux-gnu
root@10# ln -s libtinfo.so.6 libtinfo.so.5