mysql安装

需求:
在新购买的阿里云服务器centOs 7上安装mysql-5.6.41-linux-glibc2.12-x86_64.tar.gz


1.下载mysql压缩包,并上传至linux服务器
在地址下载对应版本的文件后,上传到服务器。


2.解压
进入文件所在目录,执行tar -xzvf mysql-5.6.41-linux-glibc2.12-x86_64.tar.gz


3.移动解压后的文件
mv mysql-5.6.41-linux-glibc2.12-x86_64 /usr/local/mysql


4.添加用户组和用户
groupadd mysql
useradd -g mysql mysql


5.安装
cd /usr/local/mysql/
chown -R mysql:mysql ./
注意datadir的配置,后续有一些文件的读写问题,一般是找不到文件之类的问题,将路径配置到这个目录下一般能解决问题。
./scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data/mysql
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
cp support-files/my-default.cnf /etc/my.cnf


6.修改启动脚本
vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/usr/local/mysql/datadir/mysql


7.修改mysql配置
vim /etc/my.cnf

[client]
port=3306
socket=/usr/local/mysql/data/mysql/mysql.sock
default-character-set=utf8

[mysqld]
port=3306
socket=/usr/local/mysql/data/mysql/mysql.sock
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data/mysql
max_connections = 1024
interactive_time = 86400
wait_timeout = 86400
skip-external-locking
key_buffer_size = 512M
max_connect_errors = 20
max_allowed_packet = 32M
join_buffer_size=2M
table_open_cache = 2048
sort_buffer_size = 12M
read_buffer_size = 12M
read_rnd_buffer_size = 36M
myisam_sort_buffer_size = 64M
bulk_insert_buffer_size = 64M
thread_cache_size = 200
query_cache_size = 32M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8
#set charset
character_set_server=utf8
character_set_client=utf8
collation-server=utf8_general_ci

server-id=1

innodb_buffer_pool_size = 2048M
innodb_additional_mem_pool_size = 20M
# Set .._log_file_size to 25 % of buffer pool size
innodb_log_file_size = 128M
innodb_log_buffer_size = 32M
innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
#set charset
default-character-set=utf8
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

[mysqld_safe]
log-error=/usr/local/mysql/data/mysql/mysqld.log
pid-file=/usr/local/mysql/data/mysql/mysqld.pid

8.加入环境变量
vim /etc/profile
在最后添加export PATH=$PATH:/usr/local/mysql/bin,保存退出
source /etc/profile


9.使用mysql
启动服务:service mysqld start
关闭服务:service mysqld stop
启动客户端:mysql -uroot -p


10.问题
以下是安装过程中可能会遇到一些问题及解决方案
问题:FATAL ERROR: please install the following Perl modules before executing
解决:yum -y install autoconf
问题:error while loading shared libraries: libaio.so.1
解决:yum install libaio-devel.x86_64

你可能感兴趣的:(mysql安装)