• 售前

  • 售后

热门帖子
入门百科

Linux下安装设置MySQL

[复制链接]
王丽梅 显示全部楼层 发表于 2021-10-25 19:09:42 |阅读模式 打印 上一主题 下一主题
系统:Ubuntu 16.04LTS
1\官网下载mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
2\创建工作组:
  1. $su
  2. #groupadd mysql
  3. #useradd -r -g mysql mysql
复制代码
3\创建目次
  1. #mkdir /usr/local/mysql
  2. #mkdir /usr/local/mysql/data
复制代码
4\解压mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz,并拷贝至/usr/local/mysql
  1. #tar -zxvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
  2. #cp -r /home/jieyamulu/mysql-5.7.18-linux-glibc2.5-x86_64/* /usr/local/mysql
复制代码
5\修改mysql用户对mysql以下及其子文件夹以下文件的权限,修改后可使用ll检察权限
  1. root@Ice-***:/usr/local# chown -R mysql:mysql mysql
  2. root@Ice-***:/usr/local# ll
  3. 总用量 44
  4. drwxr-xr-x 11 root root 4096 5月 19 07:39 ./
  5. drwxr-xr-x 11 root root 4096 2月 16 04:30 ../
  6. drwxr-xr-x 2 root root 4096 2月 16 04:19 bin/
  7. drwxr-xr-x 2 root root 4096 2月 16 04:19 etc/
  8. drwxr-xr-x 2 root root 4096 2月 16 04:19 games/
  9. drwxr-xr-x 2 root root 4096 2月 16 04:19 include/
  10. drwxr-xr-x 4 root root 4096 2月 16 04:23 lib/
  11. lrwxrwxrwx 1 root root   9 3月 29 14:11 man -> share/man/
  12. drwxr-xr-x 10 mysql mysql 4096 5月 19 07:48 mysql/
  13. drwxr-xr-x 2 root root 4096 2月 16 04:19 sbin/
  14. drwxr-xr-x 8 root root 4096 2月 16 04:34 share/
  15. drwxr-xr-x 2 root root 4096 2月 16 04:19 src/
  16. root@Ice-***:/usr/local# cd mysql/
  17. root@Ice-***:/usr/local/mysql# ll
  18. 总用量 64
  19. drwxr-xr-x 10 mysql mysql 4096 5月 19 07:48 ./
  20. drwxr-xr-x 11 root root  4096 5月 19 07:39 ../
  21. drwxr-xr-x 2 mysql mysql 4096 5月 19 07:48 bin/
  22. -rw-r--r-- 1 mysql mysql 17987 5月 19 07:48 COPYING
  23. drwxr-xr-x 2 mysql mysql 4096 5月 19 07:41 data/
  24. drwxr-xr-x 2 mysql mysql 4096 5月 19 07:48 docs/
  25. drwxr-xr-x 3 mysql mysql 4096 5月 19 07:48 include/
  26. drwxr-xr-x 5 mysql mysql 4096 5月 19 07:48 lib/
  27. drwxr-xr-x 4 mysql mysql 4096 5月 19 07:48 man/
  28. -rw-r--r-- 1 mysql mysql 2478 5月 19 07:48 README
  29. drwxr-xr-x 28 mysql mysql 4096 5月 19 07:48 share/
  30. drwxr-xr-x 2 mysql mysql 4096 5月 19 07:48 support-files/
复制代码
6\修改(或新建)/etc/my.cnf 配置文件
  1. root@Ice-***:/usr/local/mysql# vim /etc/my.cnf
  2. [mysqld] basedir=/usr/local/mysql/
  3. datadir=/usr/local/mysql/data
  4. :wq
复制代码
7\最关键的初始化
  1. # cd /usr/local/mysql/
  2. root@Ice-***:/usr/local/mysql# ./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
  3. 2017-05-19T00:15:46.529420Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
  4. 2017-05-19T00:15:47.066125Z 0 [Warning] InnoDB: New log files created, LSN=45790
  5. 2017-05-19T00:15:47.213711Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
  6. 2017-05-19T00:15:47.286951Z 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: 4e958344-3c28-11e7-8334-c8d3ffd2db82.
  7. 2017-05-19T00:15:47.292857Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
  8. 2017-05-19T00:15:47.294758Z 1 [Note] A temporary password is generated for root@localhost: YjaotQk*2ew4
复制代码
初始暗码要记着
这里大概会出现很多题目,比如:

Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

缺少依靠关系包

解决方法:
  1. sudo apt-get install libaio-dev
复制代码

另有大概是之前步骤不对导致了操作data文件的权限不敷等等.按照步骤来,缺少什么装什么(有提示),到了这里应该就初始化成功了,那几个Warning,值得留意的是Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.有时间可以查下是怎么回事,这条忽略也没影响.
8\不要着急启动,现在还启动不了.实验代码,将mysql下除了data文件夹外的文件变为root权限
  1. root@Ice-***:/usr/local/mysql# chown -R root .
  2. root@Ice-***:/usr/local/mysql# chown -R mysql data
复制代码
9\启动
  1. root@Ice-***:/usr/local/mysql# bin/mysqld_safe --user=mysql &
复制代码
敲回车
  1. root@Ice-***:/usr/local/mysql# /usr/local/mysql/bin/mysql -uroot -p
  2. Enter password:
  3. Welcome to the MySQL monitor. Commands end with ; or \g.
  4. Your MySQL connection id is 3
  5. Server version: 5.7.18
  6. Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
  7. Oracle is a registered trademark of Oracle Corporation and/or its
  8. affiliates. Other names may be trademarks of their respective
  9. owners.
  10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  11. mysql> show databases;
  12. ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
  13. mysql>
复制代码
10\重置暗码
  1. mysql> SET PASSWORD = PASSWORD('newpasswd');
  2. Query OK, 0 rows affected, 1 warning (0.00 sec)
  3. mysql> show databases;
  4. +--------------------+
  5. | Database      |
  6. +--------------------+
  7. | information_schema |
  8. | mysql       |
  9. | performance_schema |
  10. | sys        |
  11. +--------------------+
  12. 4 rows in set (0.00 sec)
  13. mysql> quit
  14. Bye
复制代码
11\设置开机启动
  1. root@Ice-***:/usr/local/mysql# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
  2. root@Ice-***:/usr/local/mysql# chmod 755 /etc/init.d/mysqld
复制代码
12\安装mysql-server 和 mysql-client
  1. root@Ice-***:~# apt-get install mysql-server
  2. root@Ice-***:~# apt-get install mysql-client
  3. root@Ice-***:~# apt-get install libmysqlclient-dev
  4. E: Sub-process /usr/bin/dpkg returned an error code (1)
复制代码
解决办法:

1.$ sudo mv /var/lib/dpkg/info /var/lib/dpkg/info_old //现将info文件夹更名  
2.$ sudo mkdir /var/lib/dpkg/info //再新建一个新的info文件夹  
3.$ sudo apt-get update,  
   $ apt-get -f install //修复依靠树
4.$ sudo mv /var/lib/dpkg/info/* /var/lib/dpkg/info_old //实验完上一步操作后会在新的info文件夹下天生一些文件,现将这些文件全部移到info_old文件夹下  
5.$ sudo rm -rf /var/lib/dpkg/info //把自己新建的info文件夹删掉  
6.$ sudo mv /var/lib/dpkg/info_old /var/lib/dpkg/info //把以前的info文件夹重新改回名字
末了,如果是Ubuntu系统大概无法向表中插入汉字,无法从表中查询汉字..
解决办法:

关闭数据库服务
  1. service mysql stop
  2. ~$ sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
复制代码
在[mysqld]下添加一行character_set_server=utf8
配置文件选段:
  1. [mysqld]
  2. #
  3. # * Basic Settings
  4. #
  5. user      = mysql
  6. pid-file    = /var/run/mysqld/mysqld.pid
  7. socket     = /var/run/mysqld/mysqld.sock
  8. port      = 3306
  9. basedir     = /usr
  10. datadir     = /var/lib/mysql
  11. tmpdir     = /tmp
  12. lc-messages-dir = /usr/share/mysql
  13. character_set_server=utf8 就是这一行,原来是没有的,要手动添加!
  14. skip-external-locking
  15. #
复制代码
将上述文件拷贝至/etc/mysql/my.cnf
  1. ~$ sudo cp /etc/mysql/mysql.conf.d/mysqld.cnf /etc/mysql/my.cnf
复制代码

重启数据库服务
  1. ~$ /etc/init.d/mysql restart
复制代码

如果检察字符集能得到如下效果就阐明成功了.
  1. mysql> show variables like 'collation_%';
  2. +----------------------+-----------------+
  3. | Variable_name    | Value      |
  4. +----------------------+-----------------+
  5. | collation_connection | utf8_general_ci |
  6. | collation_database  | utf8_general_ci |
  7. | collation_server   | utf8_general_ci |
  8. +----------------------+-----------------+
  9. 3 rows in set (0.00 sec)
  10. mysql> show variables like 'character_set_%';
  11. +--------------------------+----------------------------+
  12. | Variable_name      | Value           |
  13. +--------------------------+----------------------------+
  14. | character_set_client   | utf8            |
  15. | character_set_connection | utf8            |
  16. | character_set_database  | utf8            |
  17. | character_set_filesystem | binary           |
  18. | character_set_results  | utf8            |
  19. | character_set_server   | utf8            |
  20. | character_set_system   | utf8            |
  21. | character_sets_dir    | /usr/share/mysql/charsets/ |
  22. +--------------------------+----------------------------+
  23. 8 rows in set (0.01 sec)
复制代码

帖子地址: 

回复

使用道具 举报

分享
推广
火星云矿 | 预约S19Pro,享500抵1000!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

草根技术分享(草根吧)是全球知名中文IT技术交流平台,创建于2021年,包含原创博客、精品问答、职业培训、技术社区、资源下载等产品服务,提供原创、优质、完整内容的专业IT技术开发社区。
  • 官方手机版

  • 微信公众号

  • 商务合作