linux—mysql安装步骤

时间:2024-08-26 22:05:50

一、检查系统中是否已经安装过mysql

  rpm -qa | grep mysql

  如果存在,则需要删除。
  yum -y remove mysql*

  继续检查一下是否还存在mysql
  rpm -qa | grep -i mysql

二、下载rpm包。

  需要下载:
  MySQL-client-5.6.15-1.el6.x86_64.rpm
  MySQL-devel-5.6.15-1.el6.x86_64.rpm
  MySQL-server-5.6.15-1.el6.x86_64.rpm
  逐一执行命令:
  wget http://cdn.mysql.com/archives/mysql-5.6/MySQL-client-5.6.15-1.el6.x86_64.rpm

  wget http://cdn.mysql.com/archives/mysql-5.6/MySQL-devel-5.6.15-1.el6.x86_64.rpm

  wget http://cdn.mysql.com/archives/mysql-5.6/MySQL-server-5.6.15-1.el6.x86_64.rpm

三、依次安装

  rpm -ivh MySQL-server-5.6.15-1.el6.x86_64.rpm

rpm -ivh MySQL-devel-5.6.15-1.el6.x86_64.rpm

rpm -ivh MySQL-client-5.6.15-1.el6.x86_64.rpm

四、 初始化MySQL及设置密码

  cp /usr/share/mysql/my-default.cnf /etc/my.cnf

  cat /root/.mysql_secret   记录最后的密码
  mysql -p ---输入记录的密码,即可登录mysql。
  set password for 'root'@'localhost' =password('新密码');
  flush privileges;  //刷新权限设置

五、配置数据库编码格式

  登录MySQL查看用SHOW VARIABLES LIKE 'character%';下字符集,显示如下:
  +--------------------------+----------------------------+
  | Variable_name | Value |
  +--------------------------+----------------------------+
  | character_set_client | utf8 |
  | character_set_connection | utf8 |
  | character_set_database | latin1 |
  | character_set_filesystem | binary |
  | character_set_results | utf8 |
  | character_set_server | latin1 |
  | character_set_system | utf8 |
  | character_sets_dir | /usr/share/mysql/charsets/ |
  +--------------------------+----------------------------+
  character_set_database和character_set_server的默认字符集还是latin1。

  最简单的完美修改方法,修改mysql的my.cnf文件中的字符集键值(注意配置的字段细节):
  1、在[client]字段里加入default-character-set=utf8,如下:
  [client]
  port = 3306
  socket = /var/lib/mysql/mysql.sock
  default-character-set=utf8
  2、在[mysqld]字段里加入character-set-server=utf8,如下:
  [mysqld]
  port = 3306
  socket = /var/lib/mysql/mysql.sock
  character-set-server=utf8

  sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
  3、在[mysql]字段里加入default-character-set=utf8,如下:
  [mysql]
  no-auto-rehash
  default-character-set=utf8
  修改完成后,service mysql restart重启mysql服务就生效,并flush privileges;  //刷新权限设置。

  使用SHOW
VARIABLES LIKE ‘character%’;查看,发现数据库编码全已改成utf8。
  +--------------------------+----------------------------+
  | Variable_name | Value |
  +--------------------------+----------------------------+
  | character_set_client | utf8 |
  | character_set_connection | utf8 |
  | character_set_database | utf8 |
  | character_set_filesystem | binary |
  | character_set_results | utf8 |
  | character_set_server | utf8 |
  | character_set_system | utf8 |
  | character_sets_dir | /usr/share/mysql/charsets/ |
  +--------------------------+----------------------------+