1.下载安装包
MySQL 官方下载地址:
https://dev.mysql.com/downloads/mysql/
MySQL 5.7官方安装文档:
https://dev.mysql.com/doc/refman/5.7/en/binary-installation.html
2.安装依赖包
MySQL依赖于libaio 库。如果这个库没有在本地安装,数据目录初始化和后续的服务器启动步骤将会失败。请使用适当的软件包管理器进行安装。例如,在基于Yum的系统上:
shell> yum search libaio
shell> yum install libaio
3.创建一个mysql用户和组
shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
4.解压到指定目录
shell> tar -zxvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz -C /usr/local
shell> cd /usr/local
shell> mv mysql-5.7.21-linux-glibc2.12-x86_64 mysql
5.配置数据库目录
数据目录:/usr/local/mysql/data
参数文件my.cnf:/usr/local/mysql/etc/my.cnf
错误日志log-error:/usr/local/mysql/log/mysql_error.log
二进制日志log-bin:/usr/local/mysql/log/mysql_bin.log
慢查询日志slow_query_log_file://usr/local/mysql/log/mysql_slow_query.log
套接字socket文件:/usr/local/mysql/run/mysql.sock
pid文件:/usr/local/mysql/run/mysql.pid
shell> mkdir -p /usr/local/mysql/{data,log,etc,run}
shell> chown -R mysql:mysql /usr/local/mysql
shell> chmod 750 /usr/local/mysql/{data,log,etc,run}
6.配置my.cnf文件
在/usr/local/mysql/etc/下创建my.cnf文件,加入如下参数,其他参数根据需要配置
[client]
port = 3306
socket = /usr/local/mysql/run/mysql.sock
[mysqld]
port = 3306
socket = /usr/local/mysql/run/mysql.sock
pid_file = /usr/local/mysql/run/mysql.pid
datadir = /usr/local/mysql/data
default_storage_engine = InnoDB
max_allowed_packet = 128M
max_connections = 2048
open_files_limit = 65535
skip-name-resolve
lower_case_table_names=1
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
innodb_buffer_pool_size = 128M
innodb_log_file_size = 128M
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit = 0
key_buffer_size = 16M
log-error = /usr/local/mysql/log/mysql_error.log
log-bin = /usr/local/mysql/log/mysql_bin.log
slow_query_log = 1
slow_query_log_file = /usr/local/mysql/log/mysql_slow_query.log
long_query_time = 5
tmp_table_size = 16M
max_heap_table_size = 16M
query_cache_type = 0
query_cache_size = 0
server-id=1
7.设置临时密码
grep 'temporary password' /usr/local/mysql/log/mysql_error.log
8.初始化
/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql--datadir=/usr/local/mysql/data --initialize
9.将mysqld设置开启自动启动
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
10.复制配置文件my.cnf
cp /usr/local/mysql/etc/my.cnf /etc/my.cnf (提示覆盖就覆盖)
11.启动mysql服务
12.进入mysql
cd /usr/local/mysql/bin
./ mysql -u root -p(临时密码)
13.修改密码
重新设置密码
SET PASSWORD FOR'root'@localhost=PASSWORD('admin'); #对应的换成你自己的密码即可
14、开启远程权限
grant all privileges on *.* to '新用户名'@'%' identified by '新密码';
flush privileges;
15.配置环境变量
vim /etc/profile
export PATH=/usr/local/mysql/bin:$PATH
source /etc/profile
实战备注:
./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
报错解决方案
./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
yum install -y libaio //安装后在初始化就OK了
cRowiC5?_mo_
linux mysql password
set password for 'root'@'localhost'=password('Jackphp123!')
错误提示:
[root@localhost support-files]# ./mysql.server start
Starting MySQL.2017-07-10T07:02:40.832128Z mysqld_safe error: log-error set to ‘/var/log/mariadb/mariadb.log‘, however file don‘t exists. Create writable for user ‘mysql‘.
ERROR! The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid).
解决方案:
因为前期未创建 /var/log/mariadb/mariadb.log‘ 下面的 mariadb目录 ,mariadb.log 需要手工创建,完成 启动成功。
缺少libtinfo.so.5解决办法
在CentOS下,输入命令
ln -s /usr/lib/libncurses.so.5 /usr/lib/libtinfo.so.5
ln -s /usr/lib/libncurses.so.5 /lib/libtinfo.so.5
安装mysql后登录提示:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password:yes)
解决如下:
1.停止mysql服务
systemctl stop mysqld.service
2.修改配置文件无密码登录
vim /etc/my.cnf
在最后加上
skip-grant-tables
保存
3.启动mysql
systemctl start mysqld.service
4.登录mysql
mysql -u root
注意这里不要加-p
5.修改密码,mysql5.7用此语法
use mysql;
update mysql.user set authentication_string=password('123456') where user='root' ;
6.回到第二部把刚加的那句删掉
保存,重启mysql就可以了
默认配置文件路径:
配置文件:/etc/my.cnf
日志文件:/var/log//var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid
错误原因:升级了mysql没有update相应的mysql系统表结构,update完毕后重启既可解决
来源:oschina
链接:https://my.oschina.net/u/4416864/blog/3625392