mysql -uroot -p ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
mysql>create user ds@localhost identified by '123'; mysql>grant all on *.* to ds@localhost identified by '123'; mysql>grant all privileges on *.* to ds@'%' ; mysql>grant select on *.* to ds@'hostname' identified by '123' with grant option; MariaDB [mysql]> select host,user,password from mysql.user;
mysql>flush privileges;
1 2 3 4 5 6 7 8 9 10 11 12
# ubuntu - mysql8 sudo apt install mysql-server sudo cat /etc/mysql/debian.cnf #密码 mysql -u debian-sys-maint -p use mysql; ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY '123456'; FLUSH PRIVILEGES;
sudo vi /etc/mysql/my.cnf
[mysqld] bind-address=0.0.0.0
Public Key Retrieval is not allowed解决方法:
ALTER USER ‘root‘@’%’ IDENTIFIED WITH mysql_native_password BY ‘root’;
#保存配置文件并重启mysql service mariadb restart sudo service mysqld restart
#用mysql控制台登录并授权从库可以读取主库的二进制日志 mysql -u root -p mysql>grant replication slave,replication client on *.* to root@'192.168.56.108' identified by "root"; mysql>flush privileges;
#用mysql控制台登录并授权从库可以读取主库的二进制日志 mysql -u root -p mysql>grant replication slave,replication client on *.* to root@'192.168.56.109' identified by "root";
mysql>flush privileges;
#查看下log bin日志和pos值位置,并记录File 和Position的值 mysql> show master status;
change master to master_host='192.168.56.108',master_user='root',master_password='root',master_log_file='mysql-bin.000001',master_log_pos=373; start slave; show slave status\G; Slave_IO_Running: Yes Slave_SQL_Running: Yes
change master to master_host='192.168.56.109',master_user='root',master_password='root',master_log_file='mysql-bin.000001',master_log_pos=373; start slave; show slave status\G; Slave_IO_Running: Yes Slave_SQL_Running: Yes
#stop slave; #flush logs;
==== create database test;
use test;
CREATE TABLE IF NOT EXISTS `runoob_tbl`( `runoob_id` INT UNSIGNED AUTO_INCREMENT, `runoob_title` VARCHAR(100) NOT NULL, `runoob_author` VARCHAR(40) NOT NULL, `submission_date` DATE, PRIMARY KEY ( `runoob_id` ) )ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- 统计MySQL指定数据库中有多少张表 SELECT count(*) TABLES, table_schema FROM information_schema.TABLES GROUP BY table_schema; -- 统计MySQL指定数据库中表数据量 use ; select table_name,table_rows from information_schema.tables where TABLE_SCHEMA = '数据库名称' order by table_rows desc;