Linux下安装MySQL
2017年05月04日 16:09:12
阅读数:5360
安装步骤
1、下载
下载地址:http://dev.mysql.com/downloads/mysql/5.6.html#downloads
下载版本:我这里选择的5.6.33,通用版,linux下64位
也可以直接复制64位的下载地址,通过命令下载:wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz
0、卸载老版本MySQL
查找并删除mysql有关的文件
find / -name mysql
rm -rf 上边查找到的路径,多个路径用空格隔开
#或者下边一条命令即可
find / -name mysql|xargs rm -rf
Paste_Image.png
1、在安装包存放目录下执行命令解压文件:
tar -zxvf mysql-5.6.31-linux-glibc2.5-x86_64.tar.gz
Paste_Image.png
2、删除安装包,重命名解压后的文件
rm -f mysql-5.6.31-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.6.31-linux-glibc2.5-x86_64/ mysql
Paste_Image.png
3、添加mysql用户组和mysql用户
先检查是否有mysql用户组和mysql用户
groups mysql
Paste_Image.png
若无,则添加;
groupadd mysql
useradd -r -g mysql mysql
Paste_Image.png
若有,则跳过;
Paste_Image.png
4、进入mysql目录更改权限
cd mysql/
chown -R mysql .
chgrp -R mysql .
scripts/mysql_install_db --user=mysql
chown -R root .
chown -R mysql data
Paste_Image.png
5、进入到mysql目录,执行添加MySQL配置的操作
cp support-files/my-medium.cnf /etc/my.cnf
或:
cp support-files/my-default.cnf /etc/my.cnf
是否覆盖?按y 回车
6、编辑/etc/my.cnf文件;
vi /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[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 = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
# server_id = .....
socket = /tmp/mysql.sock
character-set-server = utf8
skip-name-resolve
log-err = /usr/local/mysql/data/error.log
pid-file = /usr/local/mysql/data/mysql.pid
# 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
7、初始化数据(在mysql/bin或者mysql/scripts下有个 mysql_install_db 可执行文件初始化数据库),进入mysql/bin或者mysql/scripts目录下,执行下面命令
./mysql_install_db --verbose --user=root --defaults-file=/etc/my.cnf --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql --pid-file=/usr/local/mysql/data/mysql.pid --tmpdir=/tmp
8启动MySQL
cd /usr/local/mysql
./support-files/mysql.server start
第一种报错
mkdir /var/log/mariadb
touch /var/log/mariadb/mariadb.log
chown -R mysql:mysql /var/log/mariadb/
再输入开启mysql服务, 搞定!
Paste_Image.png
杀掉后再启动即可。
mysql启动报错
[root@localhost mysql]# service mysql restart
Starting MySQL...[ERROR] The server quit without updating PID file (/usr/local/mysql/data/mysqld.pid).
解决方法 :
给予权限,执行
“chown -R mysql:mysql /usr/local/MySQL/data/”
“chmod -R 755 /usr/local/mysql/data”
然后重新启动mysqld!
MySQL启动之后再执行如下命令更改密码:
./bin/mysqladmin -u root -h localhost.localdomain password 'root'
Paste_Image.png
密码更改后即可登录MySQL
./bin/mysql -h127.0.0.1 -uroot -proot
Paste_Image.png
登录之后将其他用户的密码也可改为root
update mysql.user set password=password('root') where user='root';
flush privileges;
Paste_Image.png
7、增加远程登录权限
上一步即可本地登录,但远程登录会报错
Paste_Image.png
为解决这一问题,需要本地登陆MySQL后执行如下命令
grant all privileges on *.* to root@'%' identified by 'root';
flush privileges;
Paste_Image.png
执行之后即可远程登录
Paste_Image.png
8、将MySQL加入Service系统服务
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
service mysqld restart
service mysqld status
Paste_Image.png
Paste_Image.png
9、配置my.cnf
vim my.cnf
#添加以下两条语句并保存退出
default-character-set=utf8
lower_case_table_names=1
max_allowed_packet=100M
Paste_Image.png
配置好之后,重启mysqld服务
转载自:https://blog.csdn.net/wwd0501/article/details/71171614