码迷,mamicode.com
首页 > 数据库 > 详细

linux安装mysql详细步骤

时间:2019-11-23 12:55:08      阅读:95      评论:0      收藏:0      [点我收藏+]

标签:配置   you   文件夹   master   warning   系统版本   inno   xtend   run   

Linux自带的Mysql已经卸载干净,安装前要检查是否有系统自带的Mysql软件。

linux系统版本: CentOS 6.6  64位

安装源文件版本:mysql-cluster-gpl-7.6.11-linux-glibc2.12-x86_64.tar.gz(该包含有NDB和Mysql软件)

mysql安装位置:/software/mysql  --一般情况下放在/usr/local/mysql下

数据库文件数据位置:/data/mysql

 

1.创建安装路径和数据文件存储路径

[root@db ~]# mkdir -p /software/mysql
[root@db ~]# mkdir -p /data/mysql

2.将安装包上传到安装路径并进行解压

[root@db ~]# mv /package/mysql-cluster-gpl-7.6.11-linux-glibc2.12-x86_64.tar.gz /software/mysql

[root@db software]# chown -R mysql.mysql mysql
[root@db software]# ll
total 894336
-rwxrwxrwx. 1 mysql mysql 915792308 Sep 7 14:58 mysql

[root@db software]#tar -zvxf mysql

3.创建Mysql用户和用户组,并进行授权

[root@db ~]# groupadd mysql
[root@db ~]# useradd -r -g mysql mysql

[root@db ~]# chown -R mysql.mysql /software/mysql/
[root@db ~]# chown -R mysql.mysql /data/mysql/
[root@db ~]# chown -R mysql /software/mysql/
[root@db ~]# chown -R mysql /data/mysql/

4.更改mysql安装文件夹mysql/的权限

[root@db ~]#chmod -R 755 /software/mysql/

5.安装依赖包libaio

5.1 查询是否暗转libaio依赖包

[root@db ~]# yum search libaio
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
===================================== N/S Matched: libaio =====================================
libaio.x86_64 : Linux-native asynchronous I/O access library

Name and summary matches only, use "search all" for everything.

如果没安装,可以用下面命令安装

[root@db ~]# #yum install libaio*

 6.初始化mysql命令

[root@db bin]# pwd
/software/mysql/mysql/bin
[root@db bin]# ./mysqld --user=mysql --basedir=/software/mysql --datadir=/data/mysql --initialize
2019-11-23T04:05:05.570200Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-11-23T04:05:05.581420Z 0 [ERROR] Can‘t find error-message file ‘/software/mysql/share/errmsg.sys‘. Check error-message file location and ‘lc-messages-dir‘ configuration directive.
2019-11-23T04:05:07.993304Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-11-23T04:05:08.487409Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-11-23T04:05:08.690798Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 703b982c-0da6-11ea-a729-000c2929e347.
2019-11-23T04:05:08.703102Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed‘ cannot be opened.
2019-11-23T04:05:08.722606Z 1 [Note] A temporary password is generated for root@localhost: Pubi)p0+okYo

注意标红部分为初始化密码

7.修改mysql配置文件,用于启动mysql服务

修改前:

# Set some defaults
mysqld_pid_file_path=
if test -z "$basedir"
then
basedir=/usr/local/mysql
bindir=/usr/local/mysql/bin
if test -z "$datadir"
then
datadir=/usr/local/mysql/data
fi
sbindir=/usr/local/mysql/bin
libexecdir=/usr/local/mysql/bin
else
bindir="$basedir/bin"
if test -z "$datadir"
then
datadir="$basedir/data"
fi
sbindir="$basedir/sbin"
libexecdir="$basedir/libexec"
fi

修改后

# Set some defaults
mysqld_pid_file_path=
if test -z "$basedir"
then
basedir=/software/mysql
bindir=/software/mysql/bin
if test -z "$datadir"
then
datadir=/data/mysql/
fi
sbindir=/software/mysql/bin
libexecdir=/software/mysql/bin
else
bindir="$basedir/bin"
if test -z "$datadir"
then
datadir="$basedir/data"
fi
sbindir="$basedir/sbin"
libexecdir="$basedir/libexec"
fi

添加服务

[root@db bin]# cp /software/mysql/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@db bin]# chmod 775 /etc/init.d/mysqld

8.修改my.cnf配置文件,将下面内容覆盖到my.cnf文件

[client]
no-beep
socket =/software/mysql/mysql.sock
# pipe
# socket=0.0
port=3306
[mysql]
default-character-set=utf8
[mysqld]
basedir=/software/mysql
datadir=/data/mysql
port=3306
pid-file=/software/mysql/mysqld.pid
#skip-grant-tables
skip-name-resolve
socket = /software/mysql/mysql.sock
character-set-server=utf8
default-storage-engine=INNODB
explicit_defaults_for_timestamp = true
# Server Id.
server-id=1
max_connections=2000
query_cache_size=0
table_open_cache=2000
tmp_table_size=246M
thread_cache_size=300
#限定用于每个数据库线程的栈大小。默认设置足以满足大多数应用
thread_stack = 192k
key_buffer_size=512M
read_buffer_size=4M
read_rnd_buffer_size=32M
innodb_data_home_dir = /data/mysql
innodb_flush_log_at_trx_commit=0
innodb_log_buffer_size=16M
innodb_buffer_pool_size=256M
innodb_log_file_size=128M
innodb_thread_concurrency=128
innodb_autoextend_increment=1000
innodb_buffer_pool_instances=8
innodb_concurrency_tickets=5000
innodb_old_blocks_time=1000
innodb_open_files=300
innodb_stats_on_metadata=0
innodb_file_per_table=1
innodb_checksum_algorithm=0
back_log=80
flush_time=0
join_buffer_size=128M
max_allowed_packet=1024M
max_connect_errors=2000
open_files_limit=4161
query_cache_type=0
sort_buffer_size=32M
table_definition_cache=1400
binlog_row_event_max_size=8K
sync_master_info=10000
sync_relay_log=10000
sync_relay_log_info=10000
#批量插入数据缓存大小,可以有效提高插入效率,默认为8M
bulk_insert_buffer_size = 64M
interactive_timeout = 120
wait_timeout = 120
log-bin-trust-function-creators=1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

9启动mysql服务

[root@db software]# /etc/init.d/mysqld start
Starting MySQL.Logging to ‘/data/mysql/db.err‘.
...... SUCCESS!
[root@db software]# service mysqld status
SUCCESS! MySQL running (6138)

10.登录Mysql

10.1建立软连接生产mysql命令

[root@db ~]# ln -s /software/mysql/bin/mysql mysql

[root@db ~]# ./mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.27-ndb-7.6.11-cluster-gpl

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> set password=password(‘root‘);
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> grant all privileges on *.* to root@‘%‘ identified by ‘root‘;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)

10.2修改/software/mysql/bin/mysqld_safe文件

将文件里/usr/local/mysql改为/software/mysql

 

linux安装mysql详细步骤

标签:配置   you   文件夹   master   warning   系统版本   inno   xtend   run   

原文地址:https://www.cnblogs.com/guipeng/p/11917044.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!