CentOS7安装mysql
1、先检查是否安装过mysql,有则先删除;
rpm -qa | grep mysql
CentOS7 默认是带有Mariadb(Mariadb和mysql其实是一个东西,为什么有这个?因为防止Oracle以后闭源)
yum install mysql 这只是更新MariaDB
yum remove mysql 可以用来删除
查看是否安装mariadb
rpm -qa | grep mysql
删除mariadb
rpm -e mariadb-libs-5.5.44-1.el7_1.x86_64 此时报错
会提示有依赖于这的安装包,那么就强制卸载,不查检依赖。
rpm -e --nodeps mariadbmariadb-libs-5.5.44-1.el7_1.x86_64
2、下载mysql的repo源
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
3、安装源(如果是管理权限,可以不用sudo)
sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
如果报错如下
Error: Package: mysql-community-libs-5.6.35-2.el7.x86_64 (mysql56-community)
Requires: libc.so.6(GLIBC_2.17)(64bit)
Error: Package: mysql-community-server-5.6.35-2.el7.x86_64 (mysql56-community)
Requires: libc.so.6(GLIBC_2.17)(64bit)
Error: Package: mysql-community-server-5.6.35-2.el7.x86_64 (mysql56-community)
Requires: systemd
Error: Package: mysql-community-server-5.6.35-2.el7.x86_64 (mysql56-community)
Requires: libstdc++.so.6(GLIBCXX_3.4.15)(64bit)
Error: Package: mysql-community-client-5.6.35-2.el7.x86_64 (mysql56-community)
Requires: libc.so.6(GLIBC_2.17)(64bit)
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
解决:
#yum install glibc.i686
#yum list libstdc++*
4、检查安装的状态
rpm -qa | grep mysql
5、尝试登陆(此时密码为空)
mysql -uroot -p
会报错
解决办法:为用户分配权限
chown root /var/lib/mysql/
重启mysql服务 service mysqld restart
此时在登陆,空密码即可登陆。
6、重置root的密码
登陆mysql mysql -uroot -p
切换库 use mysql;
更新密码 update user set password=password('123456')where user='root';
退出 exit;
重启服务 service mysqld restart;
7、设置允许远程连接
登陆mysql
执行 GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "123456";
设置编码
查询编码格式
show variables like '%char%';
更改编码
vim /etc/my.conf
添加:character-set-server=utf8
重启mysql服务
安装后的默认信息:
配置文件:/etc/my.cnf
日志文件:/var/log/var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid