liunx下mysql的安装
https://blog.csdn.net/a774630093/article/details/79270080
注意版本
问题
mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
mkdir /var/log/mariadb
touch /var/log/mariadb/mariadb.log
chown -R mysql:mysql /var/log/mariadb/
https://blog.csdn.net/liukai6/article/details/78481308
====================================================
Centos 通过yum安装(RPM分发进行安装)MySQL的几个人默认目录如下:
目录 目录内容
/usr/bin 客户端程序和脚本
/usr/sbin mysqld服务器
/var/lib/mysql 日志文件,数据库文件
/usr/share/mysql 错误消息和字符集文件
/etc/my.cnf 配置文件
=========================================================
登录:
在mysql目录下:
bin/mysql -u root -p
权限:
mysql> select user ,host ,password from mysql.user;
+------+-----------+-------------------------------------------+
| user | host | password |
+------+-----------+-------------------------------------------+
| root | localhost | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| root | 127.0.0.1 | |
| root | ::1 | |
| | localhost | |
+------+-----------+-------------------------------------------+
4 rows in set (0.00 sec)
mysql的授权;
bin-log日志用于数据恢复;
yum -y install wget
grant all on *.* to user1@192.168.10.2 identified by "456"
bin/mysql -r user1 -h 192.168.10.1
主从复制其实是通过复制bin-log日志操作的。每次操作都是对地址的操作
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
log_bin=mysql-bin
server-id = 2
mysql -u user1 -p456 test -h 192.168.159.12
SHOW MASTER STATUS;
mysql> SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 | 644 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
change master to master_host='192.168.159.12', master_user='user1', master_password='456', master_port=3306, master_log_file='mysql-bin.000001', master_log_pos=120, master_connect_retry=30;
注意:
数据库唯一id得不一致
在同步开始。两数据库内容一致
[root@localhost mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.6.43-log MySQL Community Server (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> reset master;
Query OK, 0 rows affected (0.02 sec)mysql> SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 | 120 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)mysql> select * from user;
ERROR 1046 (3D000): No database selected
mysql> use test ;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
mysql> select * from user;
Empty set (0.00 sec)mysql> Ctrl-C -- exit!
Aborted
[root@localhost mysql]# mysqldump -uroot -p123456 test -l -F >/tmp/test.sql
Warning: Using a password on the command line interface can be insecure.
[root@localhost mysql]# cd /tmp
[root@localhost tmp]# ll
total 4
-rw-r--r--. 1 root root 1748 Feb 27 08:25 test.sql
drwx------. 2 root root 6 Feb 27 05:51 vmware-root_5546-2864841473
drwx------. 2 root root 6 Feb 27 04:44 vmware-root_5548-2864710406
[root@localhost tmp]# scp /tmp/test.sql 192.168.159.16:/tmp
The authenticity of host '192.168.159.16 (192.168.159.16)' can't be established.
ECDSA key fingerprint is SHA256:sgz5JH7SVjEYlDnUOqqgGQsiRaQYTvaCP2Iv2caCXE4.
ECDSA key fingerprint is MD5:df:3f:95:64:d5:41:01:5a:dd:a0:05:47:35:dc:5f:22.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.159.16' (ECDSA) to the list of known hosts.
root@192.168.159.16's password:Permission denied, please try again.
root@192.168.159.16's password:
test.sql 100% 1748 809.3KB/s 00:00
[root@localhost tmp]# service mysql restart
Redirecting to /bin/systemctl restart mysql.service
[root@localhost tmp]# cd /var/lib/mysql
[root@localhost mysql]# ll
total 110620
-rw-rw----. 1 mysql mysql 56 Feb 27 05:22 auto.cnf
-rw-rw----. 1 mysql mysql 12582912 Feb 27 08:55 ibdata1
-rw-rw----. 1 mysql mysql 50331648 Feb 27 08:55 ib_logfile0
-rw-rw----. 1 mysql mysql 50331648 Feb 27 05:22 ib_logfile1
drwx------. 2 mysql mysql 4096 Feb 27 05:22 mysql
-rw-rw----. 1 mysql mysql 167 Feb 27 08:25 mysql-bin.000001
-rw-rw----. 1 mysql mysql 143 Feb 27 08:55 mysql-bin.000002
-rw-rw----. 1 mysql mysql 120 Feb 27 08:55 mysql-bin.000003
-rw-rw----. 1 mysql mysql 57 Feb 27 08:55 mysql-bin.index
srwxrwxrwx. 1 mysql mysql 0 Feb 27 08:55 mysql.sock
drwx------. 2 mysql mysql 4096 Feb 27 05:22 performance_schema
drwx------. 2 mysql mysql 52 Feb 27 05:58 test
[root@localhost mysql]# cat auto.cnf
[auto]
server-uuid=9e18f84f-3a79-11e9-a029-005056241466
[root@localhost mysql]# ll
total 110620
-rw-rw----. 1 mysql mysql 56 Feb 27 05:22 auto.cnf
-rw-rw----. 1 mysql mysql 12582912 Feb 27 08:55 ibdata1
-rw-rw----. 1 mysql mysql 50331648 Feb 27 08:55 ib_logfile0
-rw-rw----. 1 mysql mysql 50331648 Feb 27 05:22 ib_logfile1
drwx------. 2 mysql mysql 4096 Feb 27 05:22 mysql
-rw-rw----. 1 mysql mysql 167 Feb 27 08:25 mysql-bin.000001
-rw-rw----. 1 mysql mysql 143 Feb 27 08:55 mysql-bin.000002
-rw-rw----. 1 mysql mysql 120 Feb 27 08:55 mysql-bin.000003
-rw-rw----. 1 mysql mysql 57 Feb 27 08:55 mysql-bin.index
srwxrwxrwx. 1 mysql mysql 0 Feb 27 08:55 mysql.sock
drwx------. 2 mysql mysql 4096 Feb 27 05:22 performance_schema
drwx------. 2 mysql mysql 52 Feb 27 05:58 test
[root@localhost mysql]# pwd
/var/lib/mysql
[root@localhost mysql]#
组从搭建参考文章
https://www.cnblogs.com/xhyan/p/6598992.html
错误日志查看
tail /var/log/mysqld.log
https://blog.csdn.net/xu1314/article/details/7693906
=================
一、 启动
1、使用 service 启动:service mysql start
2、使用 mysqld 脚本启动:/etc/inint.d/mysql start
3、使用 safe_mysqld 启动:safe_mysql&
二、停止
1、使用 service 启动:service mysql stop
2、使用 mysqld 脚本启动:/etc/inint.d/mysql stop
3、mysqladmin shutdown
三、重启
1、使用 service 启动:service mysql restart
2、使用 mysqld 脚本启动:/etc/inint.d/mysql restart
结果
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.159.12
Master_User: user1
Master_Port: 3306
Connect_Retry: 30
Master_Log_File: mysql-bin.000003
Read_Master_Log_Pos: 120
Relay_Log_File: mysqld-relay-bin.000005
Relay_Log_Pos: 283
Relay_Master_Log_File: mysql-bin.000003
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
分区
查看
mysql> show plugins;
+----------------------------+----------+--------------------+---------+---------+
| Name | Status | Type | Library | License |
+----------------------------+----------+--------------------+---------+---------+
| binlog | ACTIVE | STORAGE ENGINE | NULL | GPL |
| mysql_native_password | ACTIVE | AUTHENTICATION | NULL | GPL |
| sha256_password | ACTIVE | AUTHENTICATION | NULL | GPL |
| CSV | ACTIVE | STORAGE ENGINE | NULL | GPL |
| MEMORY | ACTIVE | STORAGE ENGINE | NULL | GPL |
| InnoDB | ACTIVE | STORAGE ENGINE | NULL | GPL |
| INNODB_TRX | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_LOCKS | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_LOCK_WAITS | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_CMP | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_CMP_RESET | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_CMPMEM | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_CMPMEM_RESET | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_CMP_PER_INDEX | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_CMP_PER_INDEX_RESET | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_BUFFER_PAGE | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_BUFFER_PAGE_LRU | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_BUFFER_POOL_STATS | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_TEMP_TABLE_INFO | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_METRICS | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_FT_DEFAULT_STOPWORD | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_FT_DELETED | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_FT_BEING_DELETED | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_FT_CONFIG | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_FT_INDEX_CACHE | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_FT_INDEX_TABLE | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_SYS_TABLES | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_SYS_TABLESTATS | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_SYS_INDEXES | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_SYS_COLUMNS | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_SYS_FIELDS | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_SYS_FOREIGN | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_SYS_FOREIGN_COLS | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_SYS_TABLESPACES | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_SYS_DATAFILES | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_SYS_VIRTUAL | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| MyISAM | ACTIVE | STORAGE ENGINE | NULL | GPL |
| MRG_MYISAM | ACTIVE | STORAGE ENGINE | NULL | GPL |
| PERFORMANCE_SCHEMA | ACTIVE | STORAGE ENGINE | NULL | GPL |
| ARCHIVE | ACTIVE | STORAGE ENGINE | NULL | GPL |
| BLACKHOLE | ACTIVE | STORAGE ENGINE | NULL | GPL |
| FEDERATED | DISABLED | STORAGE ENGINE | NULL | GPL |
| partition | ACTIVE | STORAGE ENGINE | NULL | GPL |
| ngram | ACTIVE | FTPARSER | NULL | GPL |
+----------------------------+----------+--------------------+---------+---------+
44 rows in set
创建hash分区
create table t2 (id int(11)) partition by hash(id) partitions 5;
底层存储结构
[root@localhost mysql]# cd test
[root@localhost test]# ll
total 1088
-rw-rw----. 1 mysql mysql 65 Feb 27 05:31 db.opt
-rw-rw----. 1 mysql mysql 8556 Feb 27 10:49 t2.frm
-rw-rw----. 1 mysql mysql 40 Feb 27 10:49 t2.par
-rw-rw----. 1 mysql mysql 98304 Feb 27 10:49 t2#P#p0.ibd
-rw-rw----. 1 mysql mysql 98304 Feb 27 10:49 t2#P#p1.ibd
-rw-rw----. 1 mysql mysql 98304 Feb 27 10:49 t2#P#p2.ibd
-rw-rw----. 1 mysql mysql 98304 Feb 27 10:49 t2#P#p3.ibd
-rw-rw----. 1 mysql mysql 98304 Feb 27 10:49 t2#P#p4.ibd
-rw-rw----. 1 mysql mysql 8556 Feb 27 08:31 user.frm
-rw-rw----. 1 mysql mysql 98304 Feb 27 09:48 user.ibd
查看帮助
mysql> ? create index
Name: 'CREATE INDEX'
Description:
Syntax:
CREATE [ONLINE | OFFLINE] [UNIQUE | FULLTEXT | SPATIAL] INDEX index_name
[index_type]
ON tbl_name (key_part,...)
[index_option]
[algorithm_option | lock_option] ...key_part:
col_name [(length)] [ASC | DESC]index_option:
KEY_BLOCK_SIZE [=] value
| index_type
| WITH PARSER parser_name
| COMMENT 'string'index_type:
USING {BTREE | HASH}algorithm_option:
ALGORITHM [=] {DEFAULT | INPLACE | COPY}lock_option:
LOCK [=] {DEFAULT | NONE | SHARED | EXCLUSIVE}Normally, you create all indexes on a table at the time the table
itself is created with CREATE TABLE. See [HELP CREATE TABLE]. This
guideline is especially important for InnoDB tables, where the primary
key determines the physical layout of rows in the data file. CREATE
INDEX enables you to add indexes to existing tables.CREATE INDEX is mapped to an ALTER TABLE statement to create indexes.
See [HELP ALTER TABLE]. CREATE INDEX cannot be used to create a PRIMARY
KEY; use ALTER TABLE instead. For more information about indexes, see
http://dev.mysql.com/doc/refman/5.6/en/mysql-indexes.html.URL: http://dev.mysql.com/doc/refman/5.6/en/create-index.html
创建索引
create index in_id on t2(id);
mysql> show index from t2;
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| t2 | 1 | in_id | 1 | id | A | 5 | NULL | NULL | YES | BTREE | | |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
1 row in set (0.00 sec)
插入数据
mysql> insert into t2 values (1),(2),(3);
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0mysql> insert into t2 values (4),(5),(6),(7);
Query OK, 4 rows affected (0.00 sec)
Records: 4 Duplicates: 0 Warnings: 0mysql> insert into t2 select * from t2;
Query OK, 7 rows affected (0.01 sec)
Records: 7 Duplicates: 0 Warnings: 0mysql> insert into t2 select * from t2;
Query OK, 14 rows affected (0.00 sec)
Records: 14 Duplicates: 0 Warnings: 0mysql> insert into t2 select * from t2;
Query OK, 28 rows affected (0.01 sec)
Records: 28 Duplicates: 0 Warnings: 0mysql> insert into t2 select * from t2;
Query OK, 56 rows affected (0.00 sec)
Records: 56 Duplicates: 0 Warnings: 0