yum安装mysql和mysql源,配置mysql

时间:2024-06-16 23:37:26
申明,不要用root安装

1. 下载mysql的repo源

$ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

2. 安装mysql-community-release-el7-5.noarch.rpm包

$ sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm

安装这个包后,会获得两个mysql的yum repo源:/etc/yum.repos.d/mysql-community.repo,/etc/yum.repos.d/mysql-community-source.repo。
3. 安装mysql
$ sudo yum install mysql-server mysql-client libmysqlclient-dev mysql-devel MySQL-python 有问题看看是不是服务没开systemctl status mysqld 如果报错说找不到申明plugin,如果用root安装是会遇到这个问题的!
可能是因为/var/lib/mysql/这个目录下面有很多文件的所有者和组不是mysql用户,改改权限试试
初始化
mysql_install_db


方法1: 用SET PASSWORD命令

  mysql -u root

  mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');

方法2:用mysqladmin

  mysqladmin -u root password "newpass"

  如果root已经设置过密码,采用如下方法

  mysqladmin -u root password oldpass "newpass"

方法3: 用UPDATE直接编辑user表

  mysql -u root

  mysql> use mysql;

  mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';

  mysql> FLUSH PRIVILEGES;

在丢失root密码的时候,可以这样

  mysqld_safe --skip-grant-tables&

  mysql -u root mysql

  mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='root';

  mysql> FLUSH PRIVILEGES;

 

vi /etc/my.cnf
# 在文件中的[mysqld]下面增加一行内容
character_set_server = utf8
systemctl restart mysqld