下载
目前官网的版本到了5.7,但是5.7的安装和5.6及之前有较大的变动,所以,这里还是选用5.6的mysql安装。下载的版本是mysql-5.6.37-linux-glibc2.12-x86_64.tar.gz,即5.6mysql版本,服务器操作系统选linux-generic,64位版本。我的操作系统是centos6.9 64位版
安装
//复制安装包到指定位置,解压,准备安装
cd /usr/local
cp /home/mysql-5.6.37-linux-glibc2.12-x86_64.tar.gz .
tar xzvf mysql-5.6.37-linux-glibc2.12-x86_64.tar.gz
rm mysql-5.6.37-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.6.37-linux-glibc2.12-x86_64 mysql
//创建mysql用户
useradd mysql
//设置mysql用户密码:
echo '123456'|passwd --stdin mysql
//设置权限:
cd /usr/local
chown -R mysql:mysql mysql/
//切换到mysql用户
su - mysql
cd /usr/local/mysql/scripts/
//安装:
./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
//安装成功的提示信息,复制在这里,以免后面用到
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:
/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h nature.dev 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 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 /usr/local/mysql/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 /usr/local/mysql/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
//设置mysql服务
cp support-files/mysql.server /etc/init.d/mysqld
//启动mysql
service mysqld start
//5.7的root密码在mysql用户目录的.mysql_secret文件中
//设置root用户密码
/usr/local/mysql/bin/mysqladmin -u root password '123456'
//设置root用户远程登陆权限
/usr/local/mysql/bin/mysql -u root -p
输入密码
下面是mysql内操作脚本:
use mysql;
update user set host='%' where user = 'root' limit 1;
flush privileges;
打完收工,至此,mysql服务可以自动启动,root用户可以远程登陆
异常解决
Installing MySQL system tables…/usr/local/mysql/bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
yum install numactl.x86_64 -y
Starting MySQL. ERROR! The server quit without updating PID file (/var/run/mysqld/mysqld.pid).
关闭selinux
查看SELinux状态:
1、/usr/sbin/sestatus -v ##如果SELinux status参数为enabled即为开启状态
SELinux status: enabled
2、getenforce ##也可以用这个命令检查
关闭SELinux:
1、临时关闭(不用重启机器):
setenforce 0 ##设置SELinux 成为permissive模式
##setenforce 1 设置SELinux 成为enforcing模式
2、修改配置文件需要重启机器:
修改/etc/selinux/config 文件
将SELINUX=enforcing改为SELINUX=disabled
重启机器即可
更改pid文件目录,及权限
配置文件更改为:
[client] #本地命令行会使用该配置
socket=/var/lib/mysql/mysql.sock # 不配置的话会找到/tmp目录下去
[mysqld]
skip-name-resolve #跳过机器名解析,解决初始化安装访问慢的问题
pid-file=/var/run/mysqld/mysqld.pid
datadir=/usr/local/mysql/data
socket=/var/lib/mysql/mysql.sock
user=mysql
log_error = /usr/local/mysql/error.log
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
调整pid文件目录权限
chown -R mysql:mysql /var/run/mysqld
chmod 755 /var/run/mysqld
mkdir /var/lib/mysql
chown -R mysql:mysql /var/lib/mysql
chmod 755 /var/lib/mysql
FATAL ERROR: please install the following Perl modules before executing /usr/local/mysql/scripts/mysql_install_db
解决方法 :安装autoconf库
命令:yum-y install autoconf //此包安装时会安装Data:Dumper模块
error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
yum install -y libaio