mysql5.6 安装
1 资源下载
你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Markdown编辑器, 可以仔细阅读这篇文章,了解一下Markdown的基本语法知识。
1.1 mysql5.6下载
下载地址: https://downloads.mysql.com/archives/community/.
说明:下载的是源码包
1.2 linux配置yum源
1.2.1 虚拟机环境yum源设置
1.2.1.1 光盘选择镜像文件
1.2.1.2 配置yum源
cd /etc/yum.repos.d/
vim rhel7.repo
输入内容如下
[rhel7]
name=rhel7
baseurl=file:///media/cdrom
enabled=1
gpgcheck=0
创建挂载点后进行挂载操作,并设置成开机自动挂载
mkdir -p /media/cdrom
mount /dev/cdrom /media/cdrom
vim /etc/fstab
最后一行加入如下内容
/dev/cdrom /media/cdrom iso9660 defaults 0 0
2 安装
2.1 安装依赖
yum install libgcc
yum install libstdc++-devel
yum install gcc
yum install gcc-c++
yum install bison
yum install ncurses-devel
yum install make
yum install cmake
或者
yum install -y libgcc libstdc++-devel gcc gcc-c++ bison ncurses-devel make cmake
2.2 创建mysql的安装目录及数据库存放目录
mkdir -p /usr/local/mysql
mkdir -p /usr/local/mysql/data
2.3 创建mysql用户及用户组
groupadd mysql
useradd -r -g mysql mysql
2.4 上传文件解压,编译
上传目录:/u01/mysql-5.6.10.tar.gz
tar -zxvf mysql-5.6.10.tar.gz
cd mysql-5.6.10/
cmake .
cmake .完成:
···
make && make install
注意事项:
重新编译时,需要清除旧的对象文件和缓存信息。编译过程中能够直观的看出编译成功没有
make clean
rm -f CMakeCache.txt
rm -rf /etc/my.cnf
2.4 修改目录权限
chown -R mysql:mysql /usr/local/mysql/
2.5 安装Mysql 5.6的源码
2.5.1 安装方式1 不指定配置文件
cp my-default.cnf /etc/my.cnf
cd /usr/local/mysql/scripts
./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
mysql_install_db 初始化数据目录.
截至5.6.8版本,在unix平台,mysql_install_db创建一个被命名为“my.cnf”默认的参数文件在base安装目录。该my.cnf是根据…/mysql/support-files/my-default.cnf所创建的。如果my.cnf已经存在,脚本会假定my.cnf正在被使用,并会创建一个被命名为“my-new.cnf”的文件。
说明:
脚本由来
mysql_install_db初始化mysql工作目录 指定配置文件
MySQL初始化脚本mysql_install_db使用简介及选项参数
参数 | 说明 |
---|---|
user | 指定以哪个操作系统用户来执行mysqld进程(使用哪个用户来运行mysql server),指定了–user=mysql之后,那么通过mysqld创建的文件或者目录都是被mysql用户拥有的 |
此处可能报错:
Can't locate Data/Dumper.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at scripts/mysql_install_db line 42.BEGIN failed--compilation aborted at scripts/mysql_install_db line 42.
原因是Fedora 19中yum的prel包中没有Dumper.pm文件。这时候只要执行以下命令就可以手动下载Dumper.pm文件,执行如下命令解决:
yum install 'perl(Data::Dumper)'
执行完成:
2.5.2 安装方式2 指定配置文件
vim /etc/my.conf
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
#socket=/tmp/mysql.sock
log-error=/usr/local/mysql/data/mysql.err
pid-file=/usr/local/mysql/data/mysql.pid
log-bin=/usr/local/mysql/binlog/binlogfile
server-id=1
#character config
character_set_server=utf8
symbolic-links=1
#优化点,不然安装时有警告
explicit_defaults_for_timestamp=true
expire_logs_days=10
max_binlog_size=100M
mkdir -p /usr/local/mysql/binlog
chown -R mysql:mysql /usr/local/mysql/binlog
cd /usr/local/mysql/scripts
./mysql_install_db --defaults-file=/etc/my.conf
提示 --basedir必须要设置
FATAL ERROR: Could not find ./bin/my_print_defaults
If you compiled from source, you need to run 'make install' to
copy the software into the correct location ready for operation.
If you are using a binary release, you must either be at the top
level of the extracted archive, or pass the --basedir option
pointing to that location.
设置basedir,和配置文件保持一致,继续执行
./mysql_install_db --defaults-file=/etc/my.conf --basedir=/usr/local/mysql
WARNING: The host 'linuxprobe.com' could not be looked up with /usr/local/mysql/bin/resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !
Installing MySQL system tables...2020-03-26 21:28:31 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
OK
Filling help tables...2020-03-26 21:28:32 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
▽
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[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
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....
# 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
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
~
~
~
~
~
~
~
~
~
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h linuxprobe.com password 'new-password'
Alternatively you can run:
/usr/local/mysql/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 . ; /usr/local/mysql/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 with the ./bin/mysqlbug script!
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
New default config file was created as /usr/local/mysql/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
2.5.3 安装方式3 mysqld
cd /usr/local/mysql
./mysqld --defaults-file=/etc/my.conf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql --initialize
此方法是5.7开始增加的,5.6不能使用
2.6 进行配置(开机自启动有问题,此处可不配置):
cd /usr/local/mysql/support-files/
cp mysql.server /etc/rc.d/init.d/mysql //复制到该目录后,才可设置自动启动
chkconfig --add mysql
chkconfig mysql on //这两行代码是chkconfig设置MySql自动启动
3 启动和mysql命令配置
service mysql start
进入mysql
/usr/local/mysql/bin/mysql
输入全路径麻烦,将mysql命令链接到/usr/bin目录下
ln -s /usr/local/mysql/bin/mysql /usr/bin
4 启动设置密码
mysql
mysql>use mysql;
mysql>use mysql;
mysql>update user set password=PASSWORD('password') where user='root' and host='root' or host='localhost';
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY 'password' WITH GRANT OPTION;
mysql>flush privileges;
mysql>quit
本机登录
mysql -u root -h localhost -ppassword
其他机器登录
mysql -u root -h ip -ppassword
5 卸载
whereis mysql
全部删除
···
find / -name mysql
把除/u01/mysql外的删除
参考链接:
参考