Cnetos7 安装mysql
CentOS7默认数据库是mariadb, 但是我们经常使用的都是mysql 。
-
卸载 先停掉mysql进程 没有安装过的可以直接跳过
pkill -9 mysqld //删除进程 rpm -qa|grep -i mysql //查找mysql yum -y remove mysql-community-client-5.6.38-2.el7.x86_64 //卸载 卸载不掉的用 rpm -ev 依次卸载 直到没有
-
下载mysql的repo源
[root@localhost ~]# cd /usr/local/src/ [root@localhost src]# wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm [root@localhost src]# rpm -ivh mysql57-community-release-el7-8.noarch.rpm [root@localhost src]# yum -y install mysql-server /**默认配置文件路径: 配置文件:/etc/my.cnf 日志文件:/var/log/var/log/mysqld.log 服务启动脚本:/usr/lib/systemd/system/mysqld.service socket文件:/var/run/mysqld/mysqld.pid*/
-
配置 my.cnf
[mysqld] # # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock server_id = 1 expire_logs_days = 3 # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
-
启动mysql服务
service mysqld restart //启动mysql服务 service mysqld status // 查看mysql状态
-
重置密码
grep "password" /var/log/mysqld.log //查看临时密码 mysql -u root -p //输入密码进入 alter user 'root'@'localhost' identified by 'Root!!2018'; //必须包含 数字字母符号 flush privileges //刷新权限;
-
重置简单密码
systemctl stop mysqld.service //停止mysql服务 vi /etc/my.cnf //修改配置文件无密码登录 skip-grant-tables //在最尾部加上 保存 systemctl start mysqld.service //启动mysql mysql -u root //登录musql 此处注意不要加-p use mysql ; update mysql.user set authentication_string=password('123456') where user='root' ; //修改密码,mysql5.7用此语法 //去掉加上的 skip-grant-tables 保存 重启mysql就ok了