Linux下安装Mysql

Posted greys

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux下安装Mysql相关的知识,希望对你有一定的参考价值。

mysql5.6安装
(1) 拷贝mysql-5.6.42-linux-glibc2.12-x86_64.tar.gz
(2) tar -xvf mysql-5.6.42-linux-glibc2.12-x86_64.tar.gz
(3) 改名 mv mysql-5.6.42-linux-glibc2.12-x86_64 mysql
(4) 安装依赖包。 yum install autoconf libaio
(5) 添加用户和组,修改权限。 groupadd mysql; useradd -g mysql mysql ; chown -R mysql:mysql ./。 【/usr/local/mysql】

  注意,/var/下面的文件或文件夹也需要创建修改权限:

  创建/var/log/mariadb/mariadb.log 且执行chown -R mysql:mysql ,   chmod 777 当前目录;

  创建/var/lib/mysql目录,修改所有者


(6) 修改配置文件 my.cnf 【如果没有my.cnf,那么手动创建一个即可】

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

[mysqld]
#skip-grant-tables
# 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=/var/lib/mysql/mysql.sock
log-error=/usr/local/mysql/data/error.log
pid-file=/usr/local/mysql/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) 初始化数据库
./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/ --pid-file=/usr/local/mysql/mysql.pid
(8) 添加服务到etc目录
cp support-files/mysql.server /etc/init.d/mysql
(9) 启动服务
service mysql start

 (10)修改相关连接配置

进入到 /usr/local/mysql/bin目录 执行 ./mysql -h127.0.0.1 -uroot -p

技术图片

执行相关密码权限操作

技术图片

 连接数据库时,注意用自己配置的密码。 同时,如果是阿里云服务器,要修改安全组规则,添加出规则和入规则

 

以上是关于Linux下安装Mysql的主要内容,如果未能解决你的问题,请参考以下文章

linux下源代码搭建php环境之mysql

mysql查看版本的四种方法

Linux下基于源代码方式安装MySQL 5.6

linux下安装mysql

Linux平台下安装MySQL

下载mysql5.6源码在linux下安装