首页 > 数据库 >linux 安装 mysql 的 glibc 包

linux 安装 mysql 的 glibc 包

时间:2023-06-26 15:32:59浏览次数:46  
标签:password set glibc mysql user linux sudo root


下载mysql:

http://downloads.mysql.com/archives.php

选择一个mysql的版本,之后一定要看好,下glibc的。如:mysql-5.0.90-linux-i686-glibc23.tar.gz

本例中下载到了/media目录下,这个不是好习惯...

 

▲安装mysql:

下面是linux命令

:$ sudo groupadd mysql  
:$ sudo useradd -g mysql mysql  
:$ cd /usr/local  
:$ tar zvxf /media/mysql-5.0.90-linux-i686-glibc23.tar.gz


:$ mv mysql-5.0.90-linux-i686-glibc23 mysql



:$ cd mysql  
:$ sudo chown -R mysql .  
:$ sudo chgrp -R mysql .  
:$ scripts/mysql_install_db --user=mysql  --basedir=/usr/local/mysql  
:& cd ..  
:$ sudo chown -R root mysql .  
:$ cd mysql  
:$ sudo chown -R mysql data  
:$ bin/mysqld_safe --basedir=/usr/local/mysql --user=mysql &


 

至此,mysql安装成功。

因为在运行状态,我没有ctrl-c,只好再开一个ssh窗口...

 

▲为mysql的root用户添加密码

下面是linux命令

cd /usr/local/mysql/bin ./mysql -u root


进入mysql后:



mysql>  GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY "chang";


其实是设置了root的localhost的密码为chang
显示执行成功,然后exit退出mysql。

之后,再次登录mysql,这次要用密码了:


cd /usr/local/mysql/bin./mysql -u root -p


输入密码chang之后,可以正常登录,如下:

Welcome to the MySQL monitor.  Commands end with ; or /g.
Your MySQL connection id is 1
Server version: 5.0.90 MySQL Community Server (GPL)

Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.

 

查看一下用户信息:



mysql> select user,host,password from mysql.user;


结果如下:

+------+-----------+----------+
 | user | host      | password |
 +------+-----------+----------+
 | root | localhost |  *F05D019BA3BEC01CA9FBD4141E4EA57A28EF3EDF  |   ← (root密码为chang) 
 | root | linux        |            |   ← (root密码为空) 
 | root | 127.0.0.1 |           |   ← (root密码为空) 
 |        | localhost  |           | 
 +------+-----------+----------+

分别更改它们的密码:


mysql> set password for root@localhost=password('chang');



mysql> set password for root@linux=password('chang');


mysql> set password for [email protected]=password('chang');


再次查看用户信息会发现已经更改过来。

然后退出mysql。

 

▲把mysql做成服务



sudo cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql


启动mysql服务



sudo /etc/init.d/mysql start


这时候就可以重启机器试试了
重启后再登陆mysql,发现可以登陆。服务制作成功!

 

▲配置mysql

 


vi /etc/my.cnf


(注释:如果没有自动生成my.cnf文件,那么:安装完的mysql包下有个support-files文件夹,其中有my-huge.cnf等,将my-huge copy一份,改名为my.cnf,将其适当地修改(当然是根据你的数据库配置)然后copy至/etc/my.cnf)

打开my.cnf后

找到[client] 添加: 
default-character-set = utf8      # 默认字符集为utf8

找到[mysqld] 添加:
default-character-set = utf8       #默认字符集为utf8
init_connect = 'SET NAMES utf8' #设定连接mysql数据库时使用utf8编码,以让mysql数据库为utf8运行

 

修改好后,重新启动即可.
我这里是重启了mysql的服务:


sudo /etc/init.d/mysql restart


(有一次找不到sock,这样重启两次服务之后居然可以了!!!汗。)

 

之后进入mysql,查一下是否更改了字符集:



cd /usr/local/mysql/bin./mysql -u root -p


mysql> show variables like 'character%';

出现下面的画面:

+--------------------------+----------------------------------------+
 | Variable_name            | Value                                  |
 +--------------------------+----------------------------------------+
 | character_set_client     | utf8                                   | 
 | character_set_connection | utf8                                   | 
 | character_set_database   | utf8                                   | 
 | character_set_filesystem | binary                                 | 
 | character_set_results    | utf8                                   | 
 | character_set_server     | utf8                                   | 
 | character_set_system     | utf8                                   | 
 | character_sets_dir       | /usr/local/mysql/share/mysql/charsets/ | 
 +--------------------------+----------------------------------------+

好,数据库语言完毕。

 

▲打开mysql的远程访问mysql默认是不允许远程访问的。
用密码登陆mysql,可以正常登陆,但是换台机器用工具连,就报错:
ERROR 1130: Host 192.168.1.6 is not allowed to connect to this MySQL server

 

方法: 改表法。mysql默认是不允许远程访问的,只能在localhost访问。这个时候只要在localhost的那台电脑,登入mysql后,更改 “mysql” 数据库里的 “user” 表里的 “host” 项,从”localhost”改成”%”

mysql -u root -p
 Enter password: chang
 mysql>use mysql;
 mysql>update user set host = '%' where user = 'root';  //可能会报错
 mysql>flush privileges; 
 mysql>select host,user from user where user='root';


  

执行完上面的,就可以远程连接了!

注释:

update user set host = '%' where user = 'root'; //这个命令执行错误时,可能会报错:
ERROR 1062 (23000): Duplicate entry '%-root' for key 1;
解决方法:
1,不用管它。呵呵。
2,改成这样执行
update user set host='%' where user='root' and host='localhost';
也就是把localhost改成了所有主机。

 

 ---------------------------------------------------
之后运行app程序,报错:
ImportError: libmysqlclient_r.so.15: cannot open shared object file: No such file or directory

解决办法是把/usr/local/mysql/lib下的
libmysqlclient_r.so.15
拷贝到/usr/lib解决。

 

至此,mysql安装配置完毕!

 

 

 ================= 我是华丽的分割线 ========================

----------------------------------------------------
■附注:
附注1: 重启和关闭mysql服务
重启mysql服务
:$ sudo /etc/init.d/mysql restart
关闭mysql服务
:$ sudo /etc/init.d/mysql stop 
----------------------------------------------------
附注2: 非服务状态下,启动和停止mysql
启动mysql
代码: 
:& cd /usr/local/mysql
:& bin/mysqld_safe --basedir=/usr/local/mysql --user=mysql &

停止mysql
代码: 
:& cd /usr/local/mysql
:$ bin/mysqladmin -uroot -ppassw0rd shutdown

----------------------------------------------------
附注3: mysql命令行中文显示?号
mysql> set names utf8;

---------------------------------------------------
附注4: mysql的数据库存放路径
/var/lib/mysql

---------------------------------------------------
附注5: 从mysql中导出和导入数据
mysqldump 数据库名 > 文件名 #导出数据库
mysqladmin create 数据库名 #建立数据库
mysql 数据库名 < 文件名 #导入数据库

---------------------------------------------------
附注6: 修改mysql的root口令
sudo mysqladmin -u root -p password '你的新密码'

或者:括号里是新密码
use mysql; 
update user set Password=password('chang') where User='root'; 
flush privileges;

---------------------------------------------------
附注7: 忘了mysql的root口令怎么办
sudo /etc/init.d/mysql stop
sudo mysqld_safe --skip-grant-tables &
sudo mysqladmin -u user password 'newpassword
sudo mysqladmin flush-privileges

---------------------------------------------------
附注8: 输入要登录的mysql主机
./mysql -u root -h 127.0.0.1 -p

执行安全设置

#bin/mysql_secure_installation


NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
 
In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
 
Enter current password for root (enter for none):<---输入现在的root密码,因为我们还没设置,直接回车
OK, successfully used password, moving on...
 
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
 
Set root password? [Y/n] Y   <---是否设定root密码,当然设置了,输入Y回车
New password: <---输入root密码,并回车,输入的过程中不会有任何显示
Re-enter new password: <---再次输入root密码,并回车,输入的过程中不会有任何显示
Password updated successfully!
Reloading privilege tables..
 ... Success!
 
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
 
Remove anonymous users? [Y/n] Y <---是否删除匿名用户,删除,输入Y回车
 ... Success!
 
Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.
 
Disallow root login remotely? [Y/n] Y <---是否删禁止root用户远程登录,当然禁止,输入Y回车
 ... Success!
 
By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
 
Remove test database and access to it? [Y/n] <---是否删除测试数据库test,删除,输入Y回车
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
 
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
 
Reload privilege tables now? [Y/n] Y <---刷新权限,输入Y回车
 ... Success!
 
Cleaning up...
 
All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.
 
Thanks for using MySQL!




标签:password,set,glibc,mysql,user,linux,sudo,root
From: https://blog.51cto.com/u_16131207/6554904

相关文章

  • MySQL 8.0原理与实战一网打尽,甲骨文数据库专家硬刚5年之作
    根据权威数据库技术排名网站DB-Engines今年4月的最新数据,MySQL是全球最流行的开源数据库,没有之一。在所有数据库排名中,MySQL仅次于Oracle,“屈居”亚军之位。但大家从截图中可以看出,MySQL与Oracle的得分差距已经非常小了。“开源壮年”数据库MySQL自1995年发布1.0版本以来,迄今已经走......
  • Linux搭建C++开发环境
    Linux搭建C++开发环境https://blog.csdn.net/weixin_44666217/article/details/127594532LinuxC/C++开发环境搭建https://blog.csdn.net/zcteo/article/details/117528089 ......
  • 1.startRedmineMySQL
    #!/bin/bashdockerstopredmineMySQLdockerrm-fredmineMySQLdockerrun--privileged=true\ -idt\ -p3307:3306\ --nameredmineMySQL\ --restart=always\ -v/home/mysql/data:/var/lib/mysql\ -v/home/mysql/conf/my.cnf:/etc/mysql/......
  • 32.docker mysql 启动问题随笔
    dockercpmysql:/etc/mysql/mysql.conf.d/mysqld.cnf/home/mysql/confmv mysqld.cnfmy.cnf#!/bin/bashdockerstopMySQLdockerrm-fmysqldockerrun--privileged=true\ -idt\ -p3307:3306\ --namemysql\ --restart=always\ -v/home/my......
  • linux中,如何在/etc/hosts中将一个域名解析为多个IP地址?工作原理是什么?
    可以在/etc/hosts文件中,将一个域名配置多个IP地址 比如:[root@nccztsjb-node-23yamls]#cat/etc/hosts127.0.0.1localhostlocalhost.localdomainlocalhost4localhost4.localdomain4::1localhostlocalhost.localdomainlocalhost6localhost6.localdomain......
  • 在Linux上安装和使用免费版本的PyMol
    技术背景PyMol是一个类似于VMD的分子可视化工具,也是在PyQt的基础上开发的。但是由于其商业化运营,软件分为了教育版、开源版和商业版三个版本。其中教育版会有水印,商业版要收费,但是官方不提供开源版本的安装方法。按照参考链接1的内容,可以在Windows系统上面安装一个开源版本的PyMo......
  • Linux top详解
    lnux下用top命令查看cpu利用率超过100%  这里显示的所有的cpu加起来的使用率,说明你的CPU是多核,你运行top后按大键盘1看看,可以显示每个cpu的使用率,top里显示的是把所有使用率加起来。注意:按下1后显示的是逻辑cpu的个数,并不代表cpu的真实核数。 第一行:top-11:09:......
  • mysql 8.0.26以下版本的bug
    ############################## https://bugs.mysql.com/bug.php?id=103636               ####################################......
  • C# 实现 Linux 视频聊天、远程桌面(源码,支持信创国产化环境,银河麒麟,统信UOS)
        园子里的有朋友在下载并了解了《C#实现Linux视频会议(源码,支持信创环境,银河麒麟,统信UOS)》中提供的源码后,留言给我说,这个视频会议有点复杂了,代码比较多,看得有些费劲。问我能不能整个简单点的Demo,只要有视频聊天和远程桌面的功能就可以。于是,我就又写了一个Demo来供大......
  • mysql锁
    1.表锁:locktablest1read,t2write;如果在某个线程A中执行这个语句,则其他线程【写t1】,【读写t2】的语句都会被阻塞。同时,线程A在执行unlocktables之前,也只能执行【读t1】,【读写t2】的操作。 2.行锁1)在InnoDB事务中,行锁是在需要的时候才加上的,但并不是不......