安装方式有两种 第一种 使用yum 安装,第二种 编译安装
第一种 使用yum 安装========================================================================================>
1.新开的服务器,需要检测系统是否自带安装mysql
# yum list installed | grep mysql
2.如果发现有系统自带mysql,则先删除
# yum -y remove mysql-libs.x86_64
3.在你存放文件的目录下执行,由于使用的mysql的yum源服务器在国外,所以下载速度会比较慢,你可以安需求选择 mysql5.6 79M, 或mysql5.7 182M
# wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
4.接着执行这句,解释一下,这个rpm还不是mysql的安装文件,只是两个yum源文件,执行后,在/etc/yum.repos.d/ 这个目录下多出mysql-community-source.repo和mysql-community.repo
# rpm -ivh mysql-community-release-el6-5.noarch.rpm
5.这个时候,可以用yum repolist mysql这个命令查看一下是否已经有mysql可安装文件
#yum repolist all | grep mysql
6.安装mysql 服务器命令 一路yes:
# yum install mysql-community-server
7.安装成功后
# service mysqld start
8.由于mysql刚刚安装完的时候,mysql的root用户的密码默认是空的,所以我们需要及时用mysql的root用户登录(第一次回车键,不用输入密码),并修改密码
# mysql -u root # use mysql; # update user set password=PASSWORD("这里输入root用户密码") where User='root'; # flush privileges;
9.查看mysql是否自启动,并且设置开启自启动命令
# chkconfig --list | grep mysqld # chkconfig mysqld on
10.mysql安全设置 系统会一路问你几个问题自己翻译,基本上一路yes
# mysql_secure_installation
第二种 编译安装 ========================================================================================>
1.由于我安装了mariadb 所以 先将 (没有安装 mariadb 的请跳过这一步)
my.cnf 重命名 my.cnf.mariadb my.cnf.d 重命名 my.cnf.d.mariadb #没有的话自行略过此步 如果你想运行多个实例的话 其实也可以像这样子 1 mysqld_safe 启动的时候指定 #你可以使用指定my.cnf的参数,例如 : mysqld_safe --defaults-file=/etc/mysql.cnf #或者 安装的时候指定 /usr/local/mysql/scripts/mysql_install_db \ --defaults-file=/var/mysql/my.cnf \ --basedir=/usr/local/mysql \ --datadir=/usr/local/mysql/data \ --user=mysql
开始安装MYSQL 编译安装
2 回到家目录
cd /home
3.下载源码
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.23.tar.gz
4.解压
tar zxvf mysql-5.6.23.tar.gz
5.安装必要的依赖包
sudo yum install cmake gcc-c++ ncurses-devel perl-Data-Dumper
6.进入mysql源码目录,生成makefile
cmake .
7.编译 及安装
sudo make && sudo make install
8.按装路径
mysql将会安装到/usr/local/mysql路径。
9.添加mysql用户和组
sudo groupadd mysql sudo useradd -r -g mysql mysql
因为我安装了mariadb 已经有了用户组和用户名 所以掠过
10.修改目录和文件权限,安装默认数据库
cd /usr/local/mysql sudo chown -R mysql . sudo chgrp -R mysql . sudo scripts/mysql_install_db --user=mysql sudo chown -R root . sudo chown -R mysql data
11.创建my.cnf
注我在这里禁用了
innodb
顺带开启了错误调试
关键配置如下
datadir =/usr/local/mysql/data socket =/tmp/mysql.sock log-error=/home/mysqlerror.log default-storage-engine=MYISAM skip-innodb default-tmp-storage-engine=MYISAM
以下是完整配置
#my.cnf from www.weicot.com is test config #dvice on how to change settings please see # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html [mysqld] default-storage-engine=MYISAM skip-innodb default-tmp-storage-engine=MYISAM # 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 # These are commonly set, remove the # and set as required. # basedir = ..... datadir =/usr/local/mysql/data # port = ..... # server_id = ..... socket =/var/lib/mysql/mysql.sock # 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 max_connection = 10000 sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES #binary log log-bin = mysql-bin binlog_format = mixed expire_logs_day = 30 log-error=/home/mysqlerror.log #slow query log slow_query_log = 1 slow_query_log_file = /var/log/mysql/slow.log long_query_time = 3 log-queries-not-using-indexes log-slow-admin-statements loose-innodb-trx=0 loose-innodb-locks=0 loose-innodb-lock-waits=0 loose-innodb-cmp=0 loose-innodb-cmp-per-index=0 loose-innodb-cmp-per-index-reset=0 loose-innodb-cmp-reset=0 loose-innodb-cmpmem=0 loose-innodb-cmpmem-reset=0 loose-innodb-buffer-page=0 loose-innodb-buffer-page-lru=0 loose-innodb-buffer-pool-stats=0 loose-innodb-metrics=0 loose-innodb-ft-default-stopword=0 loose-innodb-ft-inserted=0 loose-innodb-ft-deleted=0 loose-innodb-ft-being-deleted=0 loose-innodb-ft-config=0 loose-innodb-ft-index-cache=0 loose-innodb-ft-index-table=0 loose-innodb-sys-tables=0 loose-innodb-sys-tablestats=0 loose-innodb-sys-indexes=0 loose-innodb-sys-columns=0 loose-innodb-sys-fields=0 loose-innodb-sys-foreign=0 loose-innodb-sys-foreign-cols=0
启动
/usr/local/mysql/bin/mysqld_safe --user=mysql &
报错一 说磁盘不够用
于是我把桌面环境卸了 够的话直接略过
yum groupremove 'X Window System' -y
报错 二
2016-03-07 16:19:53 23672 [Note] Plugin 'INNODB_SYS_FOREIGN' is disabled. 2016-03-07 16:19:53 23672 [Note] Plugin 'INNODB_SYS_FOREIGN_COLS' is disabled. /usr/local/mysql/bin/mysqld: Table 'mysql.plugin' doesn't exist 2016-03-07 16:19:53 23672 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it. 2016-03-07 16:19:53 23672 [Warning] /usr/local/mysql/bin/mysqld: unknown variable 'loose-innodb-ft-inserted=0' /usr/local/mysql/bin/mysqld: File '/var/log/mysql/slow.log' not found (Errcode: 2 - No such file or directory) 2016-03-07 16:19:53 23672 [ERROR] Could not open /var/log/mysql/slow.log for logging (error 2). Turning logging off for the whole duration of the MySQL server process. To turn it on again: fix the cause, shutdown the MySQL server and restart it. 2016-03-07 16:19:53 23672 [Note] Recovering after a crash using mysql-bin 2016-03-07 16:19:53 23672 [Note] Server hostname (bind-address): '*'; port: 3306 2016-03-07 16:19:53 23672 [Note] IPv6 is available. 2016-03-07 16:19:53 23672 [Note] - '::' resolves to '::'; 2016-03-07 16:19:53 23672 [Note] Server socket created on IP: '::'. 2016-03-07 16:19:53 23672 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist 160307 16:19:53 mysqld_safe mysqld from pid file /usr/local/mysql/data/localhost.localdomain.pid ended 160307 16:20:55 [ERROR] /usr/libexec/mysqld: unknown variable 'default-tmp-storage-engine=MYISAM' 160307 16:20:55 [ERROR] Aborting
就这条条
2016-03-07 16:19:53 23672 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist #安装 scripts/mysql_install_db --user=mysql --ldata=/usr/local/mysql/data root@weicot mysql]# scripts/mysql_install_db --user=mysql --ldata=/usr/local/mysql/data Installing MySQL system tables...OK Filling help tables...OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: ./bin/mysqladmin -u root password 'new-password' ./bin/mysqladmin -u root -h 127.0.0.1 password 'new-password' Alternatively you can run: ./bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with: cd . ; ./bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd mysql-test ; perl mysql-test-run.pl Please report any problems at http://bugs.mysql.com/ The latest information about MySQL is available on the web at http://www.mysql.com Support MySQL by buying support/licenses at http://shop.mysql.com WARNING: Found existing config file ./my.cnf on the system. Because this file might be in use, it was not replaced, but was used in bootstrap (unless you used --defaults-file) and when you later start the server. The new default config file was created as ./my-new.cnf, please compare it with your file and take the changes you need. WARNING: Default config file /etc/my.cnf exists on the system This file will be read by default by the MySQL server If you do not want to use this, either remove it, or use the --defaults-file argument to mysqld_safe when starting the server
现在 就基本可用了
[root@localhost bin]# ./mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.6.23-log Source distribution Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
一些权限问题
如果启动不了的话 日志又只有这个的话 多半是权限的问题
你可以切换到 su mysql 进行启动
170520 09:02:54 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data 170520 09:02:54 mysqld_safe mysqld from pid file /usr/local/mysql/data/cl.pid ended
CentOS7 不能使用service控制mysql服务,而源码安装的mysql也没有提供Systemd的控制脚本。
于是编辑/etc/rc.d/rc.local文件,添加mysql的开机启动命令。
/usr/local/mysql/bin/mysqld_safe --user=mysql & #/etc/rc.d/rc.local添加可执行权限 sudo chmod a+x /etc/rc.d/rc.local #修改root密码 /usr/loca/mysql/bin/mysql -uroot use mysql; UPDATE user SET password = PASSWORD('root') WHERE user = 'root'; GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY 'weicot'; FLUSH PRIVILEGES;
将Mysql 命令行加入Linux 环境变量
export PATH=$PATH:/usr/local/mysql/bin
mysql 设置字符集相关 mysql 设置字符集为UTF-8
默认编码
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/local/mysql/share/charsets/ | +--------------------------+----------------------------------+
部分 mysqld直接放在了mysql.conf.d文件夹下的mysqld.cnf里面,打开文件备注里面写到
# You can copy this to one of: # - "/etc/mysql/my.cnf" to set global options, # - "~/.my.cnf" to set user-specific options.
返回上一层目录,将my.cnf重新配置,添加了utf8设置
... # Remember to edit /etc/mysql/debian.cnf when changing the socket location. [client] ##port = 3306 ##socket = /var/lib/mysql/mysql.sock default-character-set=utf8 [mysqld] character-set-server=utf8 collation-server=utf8_general_ci [mysql] no-auto-rehash default-character-set=utf8 ...
重启mysql服务,
mysql> show variables like '%character%'; +--------------------------+----------------------------+ | 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/ | +--------------------------+----------------------------+ 8 rows in set (0.01 sec)
ps. 在设置utf8之前,如果已经创建了数据库,那之前的数据库编码依旧保持之前的状态,直接插入中文仍旧会报错。最好重新创建,并在数据库创建的时候就指明编码状态。
CREATE DATABASE test DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
完整的环境搭建教程 以及配置 和启用InnoDB 教程
Centos7+Mysql/MariaDB+sendMail+Nginx+PHP 环境搭建一条龙
MYSQL 5.6 安装 启用 和配置 InnoDB 等
一些其他命令
centos安装是是使用linux text 模式安装没有安装xwindows界面。现在要使用,使用yum安装。
1.登录系统,使用yum 安装
#yum groupinstall ‘X Window System’ -y
2.安装GNOME桌面环境
#yum groupinstall ‘GNOME Desktop Environment’ -y
3.如果安装KDE桌面环境
#yum groupinstall ‘KDE (K Desktop Environment)’ -y
4.卸载GNOME桌面环境
#yum groupremove “GNOME Desktop Environment”
5.卸载KDE桌面环境
#yum groupremove “KDE (K Desktop Environment)”
6.卸载Xwindows
yum groupremove ‘X Window System’ -y
转载请注明:(●--●) Hello.My Weicot » liunx 下 或centos7 下安装 MySQL-5.6