参考来源:

https://blog.csdn.net/liuxw1/article/details/81434005 https://blog.csdn.net/cheng649090216/article/details/79246333 https://dev.mysql.com/downloads/mysql/5.7.html https://www.jianshu.com/p/0f8213da9f20

mysql 完全卸载步骤-mac系统

  1. brew remove mysql
  2. brew cleanup
  3. launchctl unload -w ~/Library/LaunchAgents/com.mysql.mysqld.plist
  4. rm ~/Library/LaunchAgents/com.mysql.mysqld.plist
  5. sudo rm -rf /usr/local/var/mysql
  6. sudo rm -rf /usr/local/mysql*
  7. sudo rm -rf /Library/StartupItems/MySQLCOM
  8. sudo rm -rf /Library/PreferencePanes/My*
  9. sudo rm -rf ~/Library/PreferencePanes/My*
  10. sudo rm -rf /Library/Receipts/mysql*
  11. sudo rm -rf /Library/Receipts/MySQL*
  12. sudo rm -rf /var/db/receipts/com.mysql.*

mysql centos系统安装

cat /etc/redhat-releaseCentOS 系统版本:Linux release 7.9.2009 (Core)

mysql关于mysqld_safe的总结

http://blog.itpub.net/30126024/viewspace-2221483/

  1. wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
  2. yum localinstall -y mysql57-community-release-el7-11.noarch.rpm
  3. yum repolist enabled | grep "mysql.*-community.*"
  4. # 我这次按照查询的版本号:5.7.36-1.el7
  5. yum install -y mysql-community-server
  6. systemctl status mysqldservice mysqld status
  7. systemctl start mysqld
  8. systemctl restart mysqld
  9. 获取密码:grep 'temporary password' /var/log/mysqld.log
  10. mysql -uroot -p
  11. set global validate_password_policy=0;
  12. set global validate_password_length=4;
  13. alter user 'root'@'localhost' identified by 'root';
  14. use mysql
  15. update user set host='%' where user ='root';
  16. exit
  17. systemctl restart mysqld
  18. systemctl enable mysqld
  19. systemctl daemon-reload

配置文件调整vi /etc/my.cnf

  1. [mysqld]
  2. max_connections=200
  3. max_connect_errors=10
  4. character-set-server=utf8mb4
  5. default-storage-engine=INNODB
  6. [mysql]
  7. default-character-set=utf8mb4
  8. [mysql.server]
  9. default-character-set=utf8mb4
  10. [mysql_safe]
  11. default-character-set=utf8mb4
  12. [client]
  13. port=3306
  14. default-character-set=utf8mb4

mysql mac系统brew安装步骤

brew 安装 mysql@5.7

  1. brew search mysql
  2. brew install mysql@5.7
  3. ln -sfv /usr/local/opt/mysql@5.7/*.plist ~/Library/LaunchAgents
  4. my.cnf 配置文件找到写入内容(可忽略)
  5. mysql.server start

接下来设置mysql密码

  1. mysql -uroot
  2. show databases;
  3. use mysql
  4. update user set authentication_string = password('root') where User='root';

刷新权限

  1. flush privileges;

重启mysql服务

  1. mysql.server stop
  2. mysql.server start --skip-grant-tables (安全模式启动)

mysql my.cnf 加载顺序

  1. /etc/my.cnf
  2. /etc/mysql/my.cnf
  3. /usr/local/etc/my.cnf
  4. ~/.my.cnf

my.cnf mac配置文件内容

  1. # my.cnf mac配置文件内容
  2. # Example MySQL config file for medium systems.
  3. #
  4. # This is for a system with little memory (32M - 64M) where MySQL plays
  5. # an important part, or systems up to 128M where MySQL is used together with
  6. # other programs (such as a web server)
  7. #
  8. # MySQL programs look for option files in a set of
  9. # locations which depend on the deployment platform.
  10. # You can copy this option file to one of those
  11. # locations. For information about these locations, see:
  12. # http://dev.mysql.com/doc/mysql/en/option-files.html
  13. #
  14. # In this file, you can use all long options that a program supports.
  15. # If you want to know which options a program supports, run the program
  16. # with the "--help" option.
  17. # The following options will be passed to all MySQL clients
  18. [client]
  19. default-character-set=utf8
  20. #password = your_password
  21. port = 3306
  22. socket = /tmp/mysql.sock
  23. # Here follows entries for some specific programs
  24. # The MySQL server
  25. [mysqld]
  26. character-set-server=utf8
  27. init_connect='SET NAMES utf8
  28. port = 3306
  29. socket = /tmp/mysql.sock
  30. skip-external-locking
  31. key_buffer_size = 16M
  32. max_allowed_packet = 1M
  33. table_open_cache = 64
  34. sort_buffer_size = 512K
  35. net_buffer_length = 8K
  36. read_buffer_size = 256K
  37. read_rnd_buffer_size = 512K
  38. myisam_sort_buffer_size = 8M
  39. character-set-server=utf8
  40. secure_file_priv=''
  41. init_connect='SET NAMES utf8'
  42. # Don't listen on a TCP/IP port at all. This can be a security enhancement,
  43. # if all processes that need to connect to mysqld run on the same host.
  44. # All interaction with mysqld must be made via Unix sockets or named pipes.
  45. # Note that using this option without enabling named pipes on Windows
  46. # (via the "enable-named-pipe" option) will render mysqld useless!
  47. #
  48. #skip-networking
  49. # Replication Master Server (default)
  50. # binary logging is required for replication
  51. log-bin=mysql-bin
  52. # binary logging format - mixed recommended
  53. binlog_format=mixed
  54. # required unique id between 1 and 2^32 - 1
  55. # defaults to 1 if master-host is not set
  56. # but will not function as a master if omitted
  57. server-id = 1
  58. # Replication Slave (comment out master section to use this)
  59. #
  60. # To configure this host as a replication slave, you can choose between
  61. # two methods :
  62. #
  63. # 1) Use the CHANGE MASTER TO command (fully described in our manual) -
  64. # the syntax is:
  65. #
  66. # CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
  67. # MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
  68. #
  69. # where you replace <host>, <user>, <password> by quoted strings and
  70. # <port> by the master's port number (3306 by default).
  71. #
  72. # Example:
  73. #
  74. # CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
  75. # MASTER_USER='joe', MASTER_PASSWORD='secret';
  76. #
  77. # OR
  78. #
  79. # 2) Set the variables below. However, in case you choose this method, then
  80. # start replication for the first time (even unsuccessfully, for example
  81. # if you mistyped the password in master-password and the slave fails to
  82. # connect), the slave will create a master.info file, and any later
  83. # change in this file to the variables' values below will be ignored and
  84. # overridden by the content of the master.info file, unless you shutdown
  85. # the slave server, delete master.info and restart the slaver server.
  86. # For that reason, you may want to leave the lines below untouched
  87. # (commented) and instead use CHANGE MASTER TO (see above)
  88. #
  89. # required unique id between 2 and 2^32 - 1
  90. # (and different from the master)
  91. # defaults to 2 if master-host is set
  92. # but will not function as a slave if omitted
  93. #server-id = 2
  94. #
  95. # The replication master for this slave - required
  96. #master-host = <hostname>
  97. #
  98. # The username the slave will use for authentication when connecting
  99. # to the master - required
  100. #master-user = <username>
  101. #
  102. # The password the slave will authenticate with when connecting to
  103. # the master - required
  104. #master-password = <password>
  105. #
  106. # The port the master is listening on.
  107. # optional - defaults to 3306
  108. #master-port = <port>
  109. #
  110. # binary logging - not required for slaves, but recommended
  111. #log-bin=mysql-bin
  112. # Uncomment the following if you are using InnoDB tables
  113. #innodb_data_home_dir = /usr/local/mysql/data
  114. #innodb_data_file_path = ibdata1:10M:autoextend
  115. #innodb_log_group_home_dir = /usr/local/mysql/data
  116. # You can set .._buffer_pool_size up to 50 - 80 %
  117. # of RAM but beware of setting memory usage too high
  118. #innodb_buffer_pool_size = 16M
  119. #innodb_additional_mem_pool_size = 2M
  120. # Set .._log_file_size to 25 % of buffer pool size
  121. #innodb_log_file_size = 5M
  122. #innodb_log_buffer_size = 8M
  123. #innodb_flush_log_at_trx_commit = 1
  124. #innodb_lock_wait_timeout = 50
  125. [mysqldump]
  126. quick
  127. max_allowed_packet = 16M
  128. [mysql]
  129. no-auto-rehash
  130. # Remove the next comment character if you are not familiar with SQL
  131. #safe-updates
  132. default-character-set=utf8
  133. [myisamchk]
  134. key_buffer_size = 20M
  135. sort_buffer_size = 20M
  136. read_buffer = 2M
  137. write_buffer = 2M
  138. [mysqlhotcopy]
  139. interactive-timeout

Windows安装Mysql

  1. path bin环境变量配置(略过)
  2. a. mysqld --initialize --console (执行完毕之后会生成初始密码)
  3. b. mysqld --install [服务名](服务名可以不加默认为mysql
  4. c. mysqld --install mysql --defaults-file="xxxx/my.ini"
  5. d. sc delete mysql [删除服务]
  6. e. net start mysql [启动MySQL的服务]

my.ini Windows配置文件内容

  1. # my.ini windows配置文件内容
  2. [mysqld]
  3. # 设置3306端口
  4. port=3306
  5. # 设置mysql的安装目录
  6. basedir=C:\Program Files\MySQL
  7. # 设置mysql数据库的数据的存放目录
  8. datadir=C:\Program Files\MySQL\Data
  9. # 允许最大连接数
  10. max_connections=200
  11. # 允许连接失败的次数。
  12. max_connect_errors=10
  13. # 服务端使用的字符集默认为utf8mb4
  14. character-set-server=utf8mb4
  15. # 创建新表时将使用的默认存储引擎
  16. default-storage-engine=INNODB
  17. # 默认使用“mysql_native_password”插件认证
  18. #mysql_native_password
  19. default_authentication_plugin=mysql_native_password
  20. # 选用sql的严格模式
  21. # sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
  22. [mysql]
  23. # 设置mysql客户端默认字符集
  24. default-character-set=utf8mb4
  25. [mysql.server]
  26. # 设置mysql客户端默认字符集
  27. default-character-set=utf8mb4
  28. [mysql_safe]
  29. default-character-set=utf8mb4
  30. [client]
  31. # 设置mysql客户端连接服务端时默认使用的端口
  32. port=3306
  33. default-character-set=utf8mb4

MySql 命令

更新域属性,’%’表示允许外部访问;

  1. update user set host='%' where user ='root';

执行以上语句之后再执行(刷新配置)

  1. FLUSH PRIVILEGES;
  2. GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION;

创建用户并给予root权限 nacos(你的用户名)

  1. CREATE USER 'nacos'@'%' IDENTIFIED BY 'nacos';
  2. GRANT ALL PRIVILEGES ON *.* TO 'nacos'@'%'WITH GRANT OPTION;

设置密码长度、安全型

  1. set global validate_password_policy=0;
  2. set global validate_password_length=4;

版本号查询

  1. select version();

提供什么存储引擎

  1. show engines;

当前默认的存储引擎

  1. show variables like '%storage_engine%';

查询数据库存储

  1. select table_schema as '数据库',
  2. table_name as '表名',
  3. table_rows as '记录数',
  4. truncate(data_length / 1024 / 1024, 2) as '数据容量(MB)',
  5. truncate(index_length / 1024 / 1024, 2) as '索引容量(MB)'
  6. from information_schema.tables
  7. where table_schema = 'xxxxxxxxxxxtable'
  8. order by data_length desc, index_length desc
  9. limit 0, 10

Mac mysql 设置可远程连接

怎么知道mysql的配置文件在哪里呢?

  1. mysql --help
  2. Default options are read from the following files in the given order:
  3. /etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf

修改mysql配置,由于是通过brew安装的mysql,配置文件在:/usr/local/etc/my.cnf;
找到:bind-address = 127.0.0.1
修改为:bind-address = 0.0.0.0 或用#注释掉
然后mysql重启:

  1. mysql.server restart